From 4d984b717c20250c83910b023aec7a3ca8439067 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Fri, 23 Jul 2021 20:38:15 -0700 Subject: [PATCH 01/11] Add gradle tasks generation to build plugin to create CG Manifest for deps --- plugins/buildsystem/build.gradle | 5 +- .../identity/buildsystem/BuildPlugin.java | 15 +++++ .../rendering/AbstractDependencyRenderer.java | 57 +++++++++++++++++++ .../rendering/ConsoleDependencyRenderer.java | 21 +++++++ .../rendering/IDependencyFormatter.java | 8 +++ .../rendering/SimpleDependencyFormatter.java | 15 +++++ .../CGManifestDependencyJsonFormatter.java | 20 +++++++ .../CGManifestDependencyRenderer.java | 47 +++++++++++++++ .../rendering/cgmanifest/CgManifest.java | 27 +++++++++ .../rendering/cgmanifest/Component.java | 16 ++++++ .../IDependencyComponentAdapter.java | 8 +++ .../cgmanifest/IMavenComponentInfo.java | 10 ++++ .../rendering/cgmanifest/MavenComponent.java | 20 +++++++ .../MavenComponentDependencyAdapter.java | 17 ++++++ .../cgmanifest/MavenComponentInfo.java | 28 +++++++++ .../rendering/cgmanifest/Registration.java | 20 +++++++ settings.gradle | 4 +- 17 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CgManifest.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Component.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponent.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentInfo.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Registration.java diff --git a/plugins/buildsystem/build.gradle b/plugins/buildsystem/build.gradle index 3c62740d..40f7b80d 100644 --- a/plugins/buildsystem/build.gradle +++ b/plugins/buildsystem/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'com.microsoft.identity' -version '0.1.1' +version '0.1.2' pluginBundle { @@ -36,6 +36,9 @@ dependencies { testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' implementation 'com.android.tools.build:gradle:4.1.0' implementation 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.1' + 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 47d66c2f..b4815164 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,9 +23,17 @@ package com.microsoft.identity.buildsystem; import com.android.build.gradle.LibraryExtension; +import com.microsoft.identity.buildsystem.rendering.AbstractDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.ConsoleDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.IDependencyFormatter; +import com.microsoft.identity.buildsystem.rendering.SimpleDependencyFormatter; +import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestDependencyJsonFormatter; +import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestDependencyRenderer; + 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 { @@ -49,6 +57,13 @@ public void apply(final Project project) { }else{ project1.getLogger().warn("DESUGARING DISABLED"); } + + final DependencyReportTask consoleTask = project.getTasks().create("printDependenciesToConsole", DependencyReportTask.class); + final IDependencyFormatter dependencyFormatter = new SimpleDependencyFormatter(); + consoleTask.setRenderer(new ConsoleDependencyRenderer(dependencyFormatter)); + + final DependencyReportTask cgManifestTask = project.getTasks().create("createDependenciesCgManifest", DependencyReportTask.class); + cgManifestTask.setRenderer(new CGManifestDependencyRenderer()); }); SpotBugs.applySpotBugsPlugin(project); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java new file mode 100644 index 00000000..e2c70680 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java @@ -0,0 +1,57 @@ +// 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 org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.tasks.diagnostics.internal.DependencyReportRenderer; +import org.gradle.api.tasks.diagnostics.internal.TextReportRenderer; + +public abstract class AbstractDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { + + @Override + public void startConfiguration(Configuration configuration) { + // We don't need to do anything here by default + } + + @Override + public void render(Configuration configuration) { + final DependencySet dependencies = configuration.getDependencies(); + dependencies.iterator().forEachRemaining(this::renderExternalDependency); + } + + @Override + public void completeConfiguration(Configuration configuration) { + // We don't need to do anything here by default + } + + private void renderExternalDependency(Dependency dependency) { + if (!(dependency instanceof ProjectDependency)) { + render(dependency); + } + } + + public abstract void render(Dependency dependency); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java new file mode 100644 index 00000000..75797834 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java @@ -0,0 +1,21 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; + +public class ConsoleDependencyRenderer extends AbstractDependencyRenderer { + + private final IDependencyFormatter mDependencyFormatter; + + public ConsoleDependencyRenderer(IDependencyFormatter dependencyFormatter) { + mDependencyFormatter = dependencyFormatter; + } + + @Override + public void render(Dependency dependency) { + render(mDependencyFormatter.formatDependency(dependency)); + } + + private void render(String formattedDependency) { + System.out.println(formattedDependency); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java new file mode 100644 index 00000000..42d163f4 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java @@ -0,0 +1,8 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; + +public interface IDependencyFormatter { + + String formatDependency(Dependency dependency); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java new file mode 100644 index 00000000..ebb225e2 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java @@ -0,0 +1,15 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; + +public class SimpleDependencyFormatter implements IDependencyFormatter { + + private static final String SEPARATOR = ":"; + + @Override + public String formatDependency(Dependency dependency) { + return dependency.getGroup() + + SEPARATOR + dependency.getName() + + SEPARATOR + dependency.getVersion(); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java new file mode 100644 index 00000000..7324fffa --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java @@ -0,0 +1,20 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.Gson; +import com.microsoft.identity.buildsystem.rendering.IDependencyFormatter; + +import org.gradle.api.artifacts.Dependency; + +public class CGManifestDependencyJsonFormatter implements IDependencyFormatter { + + private static final Gson GSON = new Gson(); + + private final IDependencyComponentAdapter mDependencyComponentAdapter = + new MavenComponentDependencyAdapter(); + + @Override + public String formatDependency(Dependency dependency) { + final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt(dependency); + return GSON.toJson(mavenComponent); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java new file mode 100644 index 00000000..ba2ce033 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -0,0 +1,47 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.Gson; +import com.microsoft.identity.buildsystem.rendering.AbstractDependencyRenderer; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Dependency; + +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; + +public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { + + private static final String CG_MANIFEST_FILE_NAME = "cgmanifest.json"; + + final CgManifest mCgManifest = new CgManifest(); + + private static final Gson GSON = new Gson(); + + private final IDependencyComponentAdapter mDependencyComponentAdapter = + new MavenComponentDependencyAdapter(); + + @Override + public void render(Dependency dependency) { + final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt(dependency); + mCgManifest.addRegistration(new Registration(mavenComponent, false)); + } + + @Override + public void completeProject(Project project) { + super.completeProject(project); + System.out.println(GSON.toJson(mCgManifest)); + dumpToFile(); + } + + private void dumpToFile() { + try { + final FileWriter fileWriter = new FileWriter(CG_MANIFEST_FILE_NAME); + PrintWriter printWriter = new PrintWriter(fileWriter); + printWriter.print(GSON.toJson(mCgManifest)); + 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..2afd45b0 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CgManifest.java @@ -0,0 +1,27 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import lombok.NonNull; + +public class CgManifest { + + @SerializedName(SerializedNames.REGISTRATIONS) + private final List mRegistrations = new ArrayList<>(); + + public void addRegistration(@NonNull final Registration registration) { + mRegistrations.add(registration); + } + + public List getRegistrations() { + return Collections.unmodifiableList(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..51fc6f96 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Component.java @@ -0,0 +1,16 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.AllArgsConstructor; + +@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/IDependencyComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java new file mode 100644 index 00000000..2ee73618 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java @@ -0,0 +1,8 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import org.gradle.api.artifacts.Dependency; + +public interface IDependencyComponentAdapter { + + T adapt(Dependency dependency); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java new file mode 100644 index 00000000..204a5fd2 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java @@ -0,0 +1,10 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +public interface IMavenComponentInfo { + String getGroupId(); + + String getArtifactId(); + + String getVersion(); + +} 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..bf29750a --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponent.java @@ -0,0 +1,20 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.Getter; +import lombok.NonNull; + +@Getter +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/MavenComponentDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java new file mode 100644 index 00000000..2775e228 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java @@ -0,0 +1,17 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import org.gradle.api.artifacts.Dependency; + +public class MavenComponentDependencyAdapter implements IDependencyComponentAdapter { + @Override + public MavenComponent adapt(Dependency dependency) { + final MavenComponentInfo mavenComponentInfo = new MavenComponentInfo( + dependency.getGroup(), + dependency.getName(), + dependency.getVersion() + ); + + final MavenComponent mavenComponent = new MavenComponent(mavenComponentInfo); + return mavenComponent; + } +} 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..04ce8ed6 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentInfo.java @@ -0,0 +1,28 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.experimental.Accessors; + +@Getter +@AllArgsConstructor +@Accessors(prefix = "m") +public class MavenComponentInfo implements IMavenComponentInfo { + + @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..5360e63b --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Registration.java @@ -0,0 +1,20 @@ +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class Registration { + + @SerializedName(SerializedNames.COMPONENT) + private final Component mComponent; + + @SerializedName(SerializedNames.DEVELOPMENT_DEPENDENCY) + private final boolean mDevelopmentDependency; + + private static class SerializedNames { + private static final String COMPONENT = "Component"; + private static final String DEVELOPMENT_DEPENDENCY = "DevelopmentDependency"; + } +} diff --git a/settings.gradle b/settings.gradle index a9223fb4..0eab5e0c 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') From 8acd34a2d8070635fdc6954eb7e9f74b8d3bb931 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Fri, 23 Jul 2021 20:39:33 -0700 Subject: [PATCH 02/11] Add licenses --- .../rendering/ConsoleDependencyRenderer.java | 22 +++++++++++++++++++ .../rendering/IDependencyFormatter.java | 22 +++++++++++++++++++ .../rendering/SimpleDependencyFormatter.java | 22 +++++++++++++++++++ .../CGManifestDependencyJsonFormatter.java | 22 +++++++++++++++++++ .../rendering/cgmanifest/CgManifest.java | 22 +++++++++++++++++++ .../rendering/cgmanifest/Component.java | 22 +++++++++++++++++++ .../IDependencyComponentAdapter.java | 22 +++++++++++++++++++ .../cgmanifest/IMavenComponentInfo.java | 22 +++++++++++++++++++ .../rendering/cgmanifest/MavenComponent.java | 22 +++++++++++++++++++ .../MavenComponentDependencyAdapter.java | 22 +++++++++++++++++++ .../cgmanifest/MavenComponentInfo.java | 22 +++++++++++++++++++ .../rendering/cgmanifest/Registration.java | 22 +++++++++++++++++++ 12 files changed, 264 insertions(+) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java index 75797834..0d32f49a 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java index 42d163f4..68b2d9de 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java index ebb225e2..bac9c705 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java index 7324fffa..10fd7868 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java @@ -1,3 +1,25 @@ +// 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; 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 index 2afd45b0..4c8f9035 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index 51fc6f96..6f69be1b 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java index 2ee73618..a9b401c8 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java @@ -1,3 +1,25 @@ +// 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 org.gradle.api.artifacts.Dependency; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java index 204a5fd2..46889f02 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java @@ -1,3 +1,25 @@ +// 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; public interface IMavenComponentInfo { 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 index bf29750a..e233683a 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java index 2775e228..7e87f5f1 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java @@ -1,3 +1,25 @@ +// 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 org.gradle.api.artifacts.Dependency; 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 index 04ce8ed6..22b66836 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index 5360e63b..9b348a33 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; From 989efe77c34f6ccdace217e6b068ed8baf91d44b Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Fri, 23 Jul 2021 20:39:40 -0700 Subject: [PATCH 03/11] Add license --- .../CGManifestDependencyRenderer.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index ba2ce033..2cebb8a5 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -1,3 +1,25 @@ +// 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; From 339eb03446c200faed9b90f74ecaa35c59790950 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Sat, 24 Jul 2021 11:28:16 -0700 Subject: [PATCH 04/11] Pretty print dependencies JSON --- .../CGManifestDependencyRenderer.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index 2cebb8a5..d3bb220b 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -23,6 +23,9 @@ 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.AbstractDependencyRenderer; import org.gradle.api.Project; @@ -38,7 +41,8 @@ public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { final CgManifest mCgManifest = new CgManifest(); - private static final Gson GSON = new Gson(); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static final JsonParser JSON_PARSER = new JsonParser(); private final IDependencyComponentAdapter mDependencyComponentAdapter = new MavenComponentDependencyAdapter(); @@ -52,15 +56,18 @@ public void render(Dependency dependency) { @Override public void completeProject(Project project) { super.completeProject(project); - System.out.println(GSON.toJson(mCgManifest)); - dumpToFile(); + final String cgManifestJson = GSON.toJson(mCgManifest); + final JsonElement cgManifestJsonElement = JSON_PARSER.parse(cgManifestJson); + final String cgManifestPrettyJson = GSON.toJson(cgManifestJsonElement); + System.out.println(cgManifestPrettyJson); + dumpToCgManifestJsonFile(cgManifestPrettyJson); } - private void dumpToFile() { + private void dumpToCgManifestJsonFile(final String text) { try { final FileWriter fileWriter = new FileWriter(CG_MANIFEST_FILE_NAME); PrintWriter printWriter = new PrintWriter(fileWriter); - printWriter.print(GSON.toJson(mCgManifest)); + printWriter.print(text); printWriter.close(); } catch (final IOException e) { throw new RuntimeException(e); From e2594d9a8062ac260d2842fc6a1257efadf630d7 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Sat, 24 Jul 2021 15:19:47 -0700 Subject: [PATCH 05/11] Print transitive dependencies with print deps task --- .../identity/buildsystem/BuildPlugin.java | 27 ++++-- .../rendering/AbstractDependencyRenderer.java | 94 +++++++++++++++++-- .../rendering/ConfigurationAdapter.java | 26 +++++ .../rendering/ConsoleDependencyRenderer.java | 12 ++- .../buildsystem/rendering/DependencyType.java | 6 ++ .../rendering/GradleDependency.java | 15 +++ .../rendering/IConfigurationAdapter.java | 8 ++ .../rendering/IDependencyFormatter.java | 4 +- .../rendering/IMavenDependency.java | 25 +++++ .../rendering/IMavenDependencyAdapter.java | 11 +++ .../rendering/MavenDependency.java | 16 ++++ .../rendering/MavenDependencyAdapter.java | 42 +++++++++ .../rendering/SimpleDependencyFormatter.java | 4 +- .../CGManifestDependencyRenderer.java | 22 ++++- .../rendering/cgmanifest/CgManifest.java | 12 ++- .../rendering/cgmanifest/Component.java | 2 + .../IDependencyComponentAdapter.java | 4 +- .../rendering/cgmanifest/MavenComponent.java | 2 + .../MavenComponentDependencyAdapter.java | 4 +- .../rendering/cgmanifest/Registration.java | 2 + .../settings/DependencyRendererSettings.java | 38 ++++++++ .../DependencyRendererSettingsAdapter.java | 22 +++++ .../DependencyRendererSettingsExtension.java} | 19 +--- .../IDependencyRendererSettingsAdapter.java | 9 ++ 24 files changed, 375 insertions(+), 51 deletions(-) create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyType.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/GradleDependency.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependency.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependency.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependencyAdapter.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsAdapter.java rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{cgmanifest/CGManifestDependencyJsonFormatter.java => settings/DependencyRendererSettingsExtension.java} (63%) create mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/IDependencyRendererSettingsAdapter.java 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 b4815164..631920e4 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,12 +23,14 @@ package com.microsoft.identity.buildsystem; import com.android.build.gradle.LibraryExtension; -import com.microsoft.identity.buildsystem.rendering.AbstractDependencyRenderer; import com.microsoft.identity.buildsystem.rendering.ConsoleDependencyRenderer; import com.microsoft.identity.buildsystem.rendering.IDependencyFormatter; import com.microsoft.identity.buildsystem.rendering.SimpleDependencyFormatter; -import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestDependencyJsonFormatter; import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettingsAdapter; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettingsExtension; +import com.microsoft.identity.buildsystem.rendering.settings.IDependencyRendererSettingsAdapter; import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; @@ -43,33 +45,44 @@ public class BuildPlugin implements Plugin { private final static String JAVA_SOURCE_COMPATIBILITY_PROPERTY = "sourceCompatibility"; private final static String JAVA_TARGET_COMPATIBILITY_PROPERTY = "targetCompatibility"; + private final IDependencyRendererSettingsAdapter mDependencyRendererSettingsAdapter = + new DependencyRendererSettingsAdapter(); + @Override public void apply(final Project project) { final BuildPluginExtension config = project.getExtensions() .create("buildSystem", BuildPluginExtension.class); + final DependencyRendererSettingsExtension dependencyRendererSettingsExtension = + project.getExtensions().create("dependencyRendering", DependencyRendererSettingsExtension.class); + project.afterEvaluate(project1 -> { - if(config.getDesugar().get()) { + if (config.getDesugar().get()) { project1.getLogger().warn("DESUGARING ENABLED"); applyDesugaringToAndroidProject(project1); applyJava8ToJavaProject(project1); - }else{ + } else { project1.getLogger().warn("DESUGARING DISABLED"); } + final DependencyRendererSettings dependencyRendererSettings = + mDependencyRendererSettingsAdapter.adapt(dependencyRendererSettingsExtension); + final DependencyReportTask consoleTask = project.getTasks().create("printDependenciesToConsole", DependencyReportTask.class); final IDependencyFormatter dependencyFormatter = new SimpleDependencyFormatter(); - consoleTask.setRenderer(new ConsoleDependencyRenderer(dependencyFormatter)); + consoleTask.setRenderer(new ConsoleDependencyRenderer( + dependencyRendererSettings, dependencyFormatter + )); final DependencyReportTask cgManifestTask = project.getTasks().create("createDependenciesCgManifest", DependencyReportTask.class); - cgManifestTask.setRenderer(new CGManifestDependencyRenderer()); + cgManifestTask.setRenderer(new CGManifestDependencyRenderer(dependencyRendererSettings)); }); SpotBugs.applySpotBugsPlugin(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/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java index e2c70680..9cb5631f 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java @@ -22,24 +22,55 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; + 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.result.DependencyResult; +import org.gradle.api.artifacts.result.ResolutionResult; import org.gradle.api.tasks.diagnostics.internal.DependencyReportRenderer; import org.gradle.api.tasks.diagnostics.internal.TextReportRenderer; +import org.gradle.internal.deprecation.DeprecatableConfiguration; + +import java.util.HashSet; +import java.util.Set; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.experimental.Accessors; + +@AllArgsConstructor +@Accessors(prefix = "m") public abstract class AbstractDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { + private final DependencyRendererSettings mDependencyRendererSettings; + + private static final IMavenDependencyAdapter sMavenDependencyAdapter = new MavenDependencyAdapter(); + + private static final IConfigurationAdapter sConfigurationAdapter = new ConfigurationAdapter(); + + public abstract void render(@NonNull final GradleDependency gradleDependency); + + private final Set mRenderedDependencies = new HashSet<>(); + @Override public void startConfiguration(Configuration configuration) { + System.out.println("Starting configuration: " + configuration.getName()); // We don't need to do anything here by default } @Override public void render(Configuration configuration) { - final DependencySet dependencies = configuration.getDependencies(); - dependencies.iterator().forEachRemaining(this::renderExternalDependency); + if (mDependencyRendererSettings.isRenderTransitiveDependencies() && canBeResolved(configuration)) { + final ResolutionResult result = configuration.getIncoming().getResolutionResult(); + final Set results = result.getAllDependencies(); + renderDependencyResultSet(configuration, results); + } else { + final DependencySet dependencies = configuration.getDependencies(); + renderDependencySet(configuration, dependencies); + } } @Override @@ -47,11 +78,62 @@ public void completeConfiguration(Configuration configuration) { // We don't need to do anything here by default } - private void renderExternalDependency(Dependency dependency) { - if (!(dependency instanceof ProjectDependency)) { - render(dependency); + private void renderDependencySet(@NonNull final Configuration configuration, + @NonNull final DependencySet dependencies) { + dependencies.iterator().forEachRemaining( + dependency -> renderDependency(configuration, dependency) + ); + } + + private void renderDependencyResultSet(@NonNull final Configuration configuration, + @NonNull final Set dependencyResults) { + dependencyResults.iterator().forEachRemaining( + dependencyResult -> renderDependencyResult(configuration, dependencyResult) + ); + } + + private void renderDependencyResult(@NonNull final Configuration configuration, + @NonNull final DependencyResult dependencyResult) { + final IMavenDependency mavenDependency = sMavenDependencyAdapter.adapt(dependencyResult); + if (mavenDependency != null) { + renderInternal(configuration, mavenDependency); } } - public abstract void render(Dependency dependency); + private void renderDependency(@NonNull final Configuration configuration, + @NonNull final Dependency dependency) { + if (shouldRender(dependency)) { + renderInternal(configuration, sMavenDependencyAdapter.adapt(dependency)); + } + } + + private boolean shouldRender(@NonNull final Dependency dependency) { + return !(dependency instanceof ProjectDependency) || + mDependencyRendererSettings.isRenderProjectDependency(); + } + + private boolean canBeResolved(Configuration configuration) { + boolean isDeprecatedForResolving = ((DeprecatableConfiguration) configuration).getResolutionAlternatives() != null; + return configuration.isCanBeResolved() && !isDeprecatedForResolving; + } + + private boolean alreadyRendered(@NonNull final GradleDependency gradleDependency) { + return mRenderedDependencies.contains(gradleDependency); + } + + private void renderInternal(@NonNull final Configuration configuration, @NonNull final IMavenDependency mavenDependency) { + final DependencyType dependencyType = sConfigurationAdapter.adapt(configuration); + + final GradleDependency gradleDependency = new GradleDependency( + dependencyType, + mavenDependency + ); + + if (alreadyRendered(gradleDependency)) { + return; + } + + render(gradleDependency); + mRenderedDependencies.add(gradleDependency); + } } diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java new file mode 100644 index 00000000..e1894d7c --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java @@ -0,0 +1,26 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Configuration; + +import lombok.NonNull; + +public class ConfigurationAdapter implements IConfigurationAdapter { + @Override + public DependencyType adapt(Configuration configuration) { + if (isRuntimeConfiguration(configuration.getName())) { + return DependencyType.RUNTIME; + } else { + return DependencyType.DEVELOPMENT; + } + } + + 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/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java index 0d32f49a..fe7ef1bb 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java @@ -22,19 +22,23 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -import org.gradle.api.artifacts.Dependency; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; + +import lombok.NonNull; public class ConsoleDependencyRenderer extends AbstractDependencyRenderer { private final IDependencyFormatter mDependencyFormatter; - public ConsoleDependencyRenderer(IDependencyFormatter dependencyFormatter) { + public ConsoleDependencyRenderer(@NonNull final DependencyRendererSettings dependencyRendererSettings, + @NonNull final IDependencyFormatter dependencyFormatter) { + super(dependencyRendererSettings); mDependencyFormatter = dependencyFormatter; } @Override - public void render(Dependency dependency) { - render(mDependencyFormatter.formatDependency(dependency)); + public void render(@NonNull GradleDependency gradleDependency) { + render(mDependencyFormatter.formatDependency(gradleDependency.getMavenDependency())); } private void render(String 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..36172a59 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyType.java @@ -0,0 +1,6 @@ +package com.microsoft.identity.buildsystem.rendering; + +public enum DependencyType { + DEVELOPMENT, + RUNTIME; +} 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..11a4f61d --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/GradleDependency.java @@ -0,0 +1,15 @@ +package com.microsoft.identity.buildsystem.rendering; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.experimental.Accessors; + +@AllArgsConstructor +@Getter +@Accessors(prefix = "m") +@EqualsAndHashCode +public class GradleDependency { + private final DependencyType mDependencyType; + private final IMavenDependency mMavenDependency; +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java new file mode 100644 index 00000000..6c8f4e84 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java @@ -0,0 +1,8 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Configuration; + +public interface IConfigurationAdapter { + + DependencyType adapt(Configuration configuration); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java index 68b2d9de..4005f409 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java @@ -22,9 +22,7 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -import org.gradle.api.artifacts.Dependency; - public interface IDependencyFormatter { - String formatDependency(Dependency dependency); + String formatDependency(IMavenDependency dependency); } 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..0af1fe86 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependency.java @@ -0,0 +1,25 @@ +package com.microsoft.identity.buildsystem.rendering; + +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..6bf3434a --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java @@ -0,0 +1,11 @@ +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.result.DependencyResult; + +public interface IMavenDependencyAdapter { + + IMavenDependency adapt(Dependency dependency); + + IMavenDependency adapt(DependencyResult dependencyResult); +} 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..3b8bc29f --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependency.java @@ -0,0 +1,16 @@ +package com.microsoft.identity.buildsystem.rendering; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.experimental.Accessors; + +@AllArgsConstructor +@Getter +@Accessors(prefix = "m") +@EqualsAndHashCode +public class MavenDependency implements IMavenDependency { + private final String mGroup; + private final String mName; + private final String mVersion; +} 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..f207b728 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependencyAdapter.java @@ -0,0 +1,42 @@ +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 lombok.NonNull; + +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); + } + + @Override + public IMavenDependency adapt(DependencyResult dependencyResult) { + if (dependencyResult instanceof ResolvedDependencyResult) { + return adapt((ResolvedDependencyResult) dependencyResult); + } else { + return null; + } + } + + private IMavenDependency adapt(ResolvedDependencyResult resolvedDependencyResult) { + final ModuleVersionIdentifier selectedModuleVersion = resolvedDependencyResult.getSelected().getModuleVersion(); + + if (selectedModuleVersion == null) { + return null; + } + + final String group = selectedModuleVersion.getGroup(); + final String name = selectedModuleVersion.getName(); + final String version = selectedModuleVersion.getVersion(); + + return new MavenDependency(group, name, version); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java index bac9c705..2fc573fb 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java @@ -22,14 +22,12 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -import org.gradle.api.artifacts.Dependency; - public class SimpleDependencyFormatter implements IDependencyFormatter { private static final String SEPARATOR = ":"; @Override - public String formatDependency(Dependency dependency) { + 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/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index d3bb220b..0690bf40 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -27,14 +27,19 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.microsoft.identity.buildsystem.rendering.AbstractDependencyRenderer; +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.DependencyRendererSettings; import org.gradle.api.Project; -import org.gradle.api.artifacts.Dependency; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import lombok.NonNull; + public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { private static final String CG_MANIFEST_FILE_NAME = "cgmanifest.json"; @@ -47,10 +52,19 @@ public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { private final IDependencyComponentAdapter mDependencyComponentAdapter = new MavenComponentDependencyAdapter(); + public CGManifestDependencyRenderer(DependencyRendererSettings dependencyRendererSettings) { + super(dependencyRendererSettings); + } + @Override - public void render(Dependency dependency) { - final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt(dependency); - mCgManifest.addRegistration(new Registration(mavenComponent, false)); + public void render(@NonNull GradleDependency gradleDependency) { + final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt( + gradleDependency.getMavenDependency() + ); + mCgManifest.addRegistration(new Registration( + mavenComponent, + gradleDependency.getDependencyType() == DependencyType.DEVELOPMENT + )); } @Override 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 index 4c8f9035..d56323de 100644 --- 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 @@ -24,23 +24,25 @@ import com.google.gson.annotations.SerializedName; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; +import java.util.HashSet; +import java.util.Set; +import lombok.EqualsAndHashCode; import lombok.NonNull; +@EqualsAndHashCode public class CgManifest { @SerializedName(SerializedNames.REGISTRATIONS) - private final List mRegistrations = new ArrayList<>(); + private final Set mRegistrations = new HashSet<>(); public void addRegistration(@NonNull final Registration registration) { mRegistrations.add(registration); } - public List getRegistrations() { - return Collections.unmodifiableList(mRegistrations); + public Set getRegistrations() { + return Collections.unmodifiableSet(mRegistrations); } private static class SerializedNames { 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 index 6f69be1b..541ac61b 100644 --- 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 @@ -25,7 +25,9 @@ import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +@EqualsAndHashCode @AllArgsConstructor public abstract class Component { diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java index a9b401c8..f382243b 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java @@ -22,9 +22,9 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering.cgmanifest; -import org.gradle.api.artifacts.Dependency; +import com.microsoft.identity.buildsystem.rendering.IMavenDependency; public interface IDependencyComponentAdapter { - T adapt(Dependency dependency); + T 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 index e233683a..55ddac3b 100644 --- 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 @@ -24,9 +24,11 @@ import com.google.gson.annotations.SerializedName; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; +@EqualsAndHashCode @Getter public class MavenComponent extends Component { diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java index 7e87f5f1..0c32482d 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java @@ -22,11 +22,11 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering.cgmanifest; -import org.gradle.api.artifacts.Dependency; +import com.microsoft.identity.buildsystem.rendering.IMavenDependency; public class MavenComponentDependencyAdapter implements IDependencyComponentAdapter { @Override - public MavenComponent adapt(Dependency dependency) { + public MavenComponent adapt(IMavenDependency dependency) { final MavenComponentInfo mavenComponentInfo = new MavenComponentInfo( dependency.getGroup(), dependency.getName(), 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 index 9b348a33..b488cd84 100644 --- 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 @@ -25,7 +25,9 @@ import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +@EqualsAndHashCode @AllArgsConstructor public class Registration { diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java new file mode 100644 index 00000000..c89c49fd --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java @@ -0,0 +1,38 @@ +// 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 lombok.Builder; +import lombok.Getter; +import lombok.experimental.Accessors; + +@Builder +@Getter +@Accessors(prefix = "m") +public class DependencyRendererSettings { + @Builder.Default + private final boolean mRenderProjectDependency = false; + + @Builder.Default + private final boolean mRenderTransitiveDependencies = true; +} 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..61a9eca6 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsAdapter.java @@ -0,0 +1,22 @@ +package com.microsoft.identity.buildsystem.rendering.settings; + +import org.gradle.api.provider.Property; + +public class DependencyRendererSettingsAdapter implements IDependencyRendererSettingsAdapter { + @Override + public DependencyRendererSettings adapt(DependencyRendererSettingsExtension extension) { + final DependencyRendererSettings.DependencyRendererSettingsBuilder builder = + DependencyRendererSettings.builder(); + + if (extension == null) { + return builder.build(); + } + + Property renderProjectDependency = extension.getRenderProjectDependency(); + if (renderProjectDependency != null && renderProjectDependency.isPresent()) { + builder.renderProjectDependency(renderProjectDependency.get()); + } + + return builder.build(); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java similarity index 63% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java index 10fd7868..e1df4475 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyJsonFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java @@ -20,23 +20,12 @@ // 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; +package com.microsoft.identity.buildsystem.rendering.settings; -import com.google.gson.Gson; -import com.microsoft.identity.buildsystem.rendering.IDependencyFormatter; +import org.gradle.api.provider.Property; -import org.gradle.api.artifacts.Dependency; +public abstract class DependencyRendererSettingsExtension { -public class CGManifestDependencyJsonFormatter implements IDependencyFormatter { + abstract public Property getRenderProjectDependency(); - private static final Gson GSON = new Gson(); - - private final IDependencyComponentAdapter mDependencyComponentAdapter = - new MavenComponentDependencyAdapter(); - - @Override - public String formatDependency(Dependency dependency) { - final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt(dependency); - return GSON.toJson(mavenComponent); - } } 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..5c209bd7 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/IDependencyRendererSettingsAdapter.java @@ -0,0 +1,9 @@ +package com.microsoft.identity.buildsystem.rendering.settings; + +public interface IDependencyRendererSettingsAdapter { + + DependencyRendererSettings adapt( + DependencyRendererSettingsExtension dependencyRendererSettingsExtension + ); + +} From 1a21e51e04b2161c70bd6c686cea4a8d5109f804 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Sat, 24 Jul 2021 15:50:28 -0700 Subject: [PATCH 06/11] Add missing licenses --- .../rendering/ConfigurationAdapter.java | 22 +++++++++++++++++++ .../buildsystem/rendering/DependencyType.java | 22 +++++++++++++++++++ .../rendering/GradleDependency.java | 22 +++++++++++++++++++ .../rendering/IConfigurationAdapter.java | 22 +++++++++++++++++++ .../rendering/IMavenDependency.java | 22 +++++++++++++++++++ .../rendering/IMavenDependencyAdapter.java | 22 +++++++++++++++++++ .../rendering/MavenDependency.java | 22 +++++++++++++++++++ .../rendering/MavenDependencyAdapter.java | 22 +++++++++++++++++++ .../rendering/cgmanifest/MavenComponent.java | 2 +- .../DependencyRendererSettingsAdapter.java | 22 +++++++++++++++++++ .../IDependencyRendererSettingsAdapter.java | 22 +++++++++++++++++++ 11 files changed, 221 insertions(+), 1 deletion(-) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java index e1894d7c..5c41a947 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java @@ -1,3 +1,25 @@ +// 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; 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 index 36172a59..0eb91492 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; public enum DependencyType { 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 index 11a4f61d..b9933652 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java index 6c8f4e84..89d091bf 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java @@ -1,3 +1,25 @@ +// 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; 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 index 0af1fe86..9cb1ef10 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; public interface IMavenDependency { 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 index 6bf3434a..2a9b25d9 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index 3b8bc29f..fc71d468 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index f207b728..89d67d89 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index 55ddac3b..d8b8a4e7 100644 --- 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 @@ -28,7 +28,7 @@ import lombok.Getter; import lombok.NonNull; -@EqualsAndHashCode +@EqualsAndHashCode(callSuper = true) @Getter public class MavenComponent extends Component { 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 index 61a9eca6..e7b7f6b4 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; 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 index 5c209bd7..a1e00b53 100644 --- 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 @@ -1,3 +1,25 @@ +// 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; public interface IDependencyRendererSettingsAdapter { From f3fd3d546e25a5d4719453cc65572ade571ad8f1 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Fri, 30 Jul 2021 14:19:07 -0700 Subject: [PATCH 07/11] Some updates to dep rendering --- .../rendering/AbstractDependencyRenderer.java | 85 +++++++++++++------ .../rendering/ConsoleDependencyRenderer.java | 11 +++ .../rendering/GradleDependency.java | 21 ++++- .../rendering/IMavenDependencyAdapter.java | 3 + .../rendering/MavenDependency.java | 8 ++ .../rendering/MavenDependencyAdapter.java | 15 ++-- .../CGManifestDependencyRenderer.java | 56 +++++++++--- .../rendering/cgmanifest/CgManifest.java | 3 +- .../rendering/cgmanifest/MavenComponent.java | 2 + .../MavenComponentDependencyAdapter.java | 3 +- .../rendering/cgmanifest/Registration.java | 12 ++- 11 files changed, 170 insertions(+), 49 deletions(-) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java index 9cb5631f..fe4f9f6e 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java @@ -24,17 +24,24 @@ import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +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; @@ -53,7 +60,9 @@ public abstract class AbstractDependencyRenderer extends TextReportRenderer impl public abstract void render(@NonNull final GradleDependency gradleDependency); - private final Set mRenderedDependencies = new HashSet<>(); + public abstract void complete(@NonNull final Collection gradleDependencies); + + private final Map mRenderedDepMap = new HashMap<>(); @Override public void startConfiguration(Configuration configuration) { @@ -61,12 +70,17 @@ public void startConfiguration(Configuration configuration) { // We don't need to do anything here by default } + @Override + public void completeProject(Project project) { + complete(mRenderedDepMap.values()); + } + + @Override public void render(Configuration configuration) { if (mDependencyRendererSettings.isRenderTransitiveDependencies() && canBeResolved(configuration)) { final ResolutionResult result = configuration.getIncoming().getResolutionResult(); - final Set results = result.getAllDependencies(); - renderDependencyResultSet(configuration, results); + result.allDependencies(dependencyResult -> renderDependencyResult(configuration, dependencyResult)); } else { final DependencySet dependencies = configuration.getDependencies(); renderDependencySet(configuration, dependencies); @@ -85,25 +99,31 @@ private void renderDependencySet(@NonNull final Configuration configuration, ); } - private void renderDependencyResultSet(@NonNull final Configuration configuration, - @NonNull final Set dependencyResults) { - dependencyResults.iterator().forEachRemaining( - dependencyResult -> renderDependencyResult(configuration, dependencyResult) - ); - } - private void renderDependencyResult(@NonNull final Configuration configuration, @NonNull final DependencyResult dependencyResult) { - final IMavenDependency mavenDependency = sMavenDependencyAdapter.adapt(dependencyResult); - if (mavenDependency != null) { - renderInternal(configuration, mavenDependency); + final IMavenDependency depToRender = sMavenDependencyAdapter.adapt(dependencyResult); + + final ResolvedComponentResult rootResult = dependencyResult.getFrom(); + + if (depToRender != null) { + IMavenDependency depRoot; + + if (rootResult.getId() instanceof ProjectComponentIdentifier && !mDependencyRendererSettings.isRenderProjectDependency()) { + depRoot = null; + } else { + depRoot = sMavenDependencyAdapter.adapt( + rootResult.getModuleVersion() + ); + } + + renderInternal(configuration, depToRender, depRoot); } } private void renderDependency(@NonNull final Configuration configuration, @NonNull final Dependency dependency) { if (shouldRender(dependency)) { - renderInternal(configuration, sMavenDependencyAdapter.adapt(dependency)); + renderInternal(configuration, sMavenDependencyAdapter.adapt(dependency), null); } } @@ -117,23 +137,36 @@ private boolean canBeResolved(Configuration configuration) { return configuration.isCanBeResolved() && !isDeprecatedForResolving; } - private boolean alreadyRendered(@NonNull final GradleDependency gradleDependency) { - return mRenderedDependencies.contains(gradleDependency); - } + private void renderInternal(@NonNull final Configuration configuration, + @NonNull final IMavenDependency mavenDependency, + @Nullable final IMavenDependency depRoot) { + final DependencyType incomingDependencyType = sConfigurationAdapter.adapt(configuration); - private void renderInternal(@NonNull final Configuration configuration, @NonNull final IMavenDependency mavenDependency) { - final DependencyType dependencyType = sConfigurationAdapter.adapt(configuration); + GradleDependency gradleDependency = mRenderedDepMap.get(mavenDependency.toString()); - final GradleDependency gradleDependency = new GradleDependency( - dependencyType, - mavenDependency - ); + if (gradleDependency == null) { + final Set depRoots = new HashSet<>(); + + if (depRoot != null) { + depRoots.add(depRoot); + } + + gradleDependency = new GradleDependency( + incomingDependencyType, + mavenDependency, + depRoots + ); + } else { + if (depRoot != null) { + gradleDependency.addRootDependency(depRoot); + } - if (alreadyRendered(gradleDependency)) { - return; + if (incomingDependencyType == DependencyType.RUNTIME) { + gradleDependency.setDependencyType(incomingDependencyType); + } } render(gradleDependency); - mRenderedDependencies.add(gradleDependency); + mRenderedDepMap.put(mavenDependency.toString(), gradleDependency); } } diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java index fe7ef1bb..0d747afe 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java @@ -24,6 +24,8 @@ import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +import java.util.Collection; + import lombok.NonNull; public class ConsoleDependencyRenderer extends AbstractDependencyRenderer { @@ -41,6 +43,15 @@ public void render(@NonNull GradleDependency gradleDependency) { render(mDependencyFormatter.formatDependency(gradleDependency.getMavenDependency())); } + @Override + public void complete(@NonNull Collection gradleDependencies) { + // don't do anything + System.out.println("Rendering all now.."); + gradleDependencies.iterator().forEachRemaining(gradleDependency -> + System.out.println(gradleDependency.toString()) + ); + } + private void render(String formattedDependency) { System.out.println(formattedDependency); } 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 index b9933652..bb754e6c 100644 --- 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 @@ -22,9 +22,12 @@ // 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; @AllArgsConstructor @@ -32,6 +35,22 @@ @Accessors(prefix = "m") @EqualsAndHashCode public class GradleDependency { - private final DependencyType mDependencyType; + private DependencyType mDependencyType; private final IMavenDependency mMavenDependency; + private final Set mDependencyRoots; + + public void addRootDependency(@NonNull final IMavenDependency mavenDependency) { + mDependencyRoots.add(mavenDependency); + } + + 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/IMavenDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java index 2a9b25d9..3f29e945 100644 --- 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 @@ -23,6 +23,7 @@ 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; public interface IMavenDependencyAdapter { @@ -30,4 +31,6 @@ public interface IMavenDependencyAdapter { IMavenDependency adapt(Dependency dependency); IMavenDependency adapt(DependencyResult dependencyResult); + + IMavenDependency adapt(ModuleVersionIdentifier moduleVersionIdentifier); } 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 index fc71d468..34c333ae 100644 --- 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 @@ -32,7 +32,15 @@ @Accessors(prefix = "m") @EqualsAndHashCode public class MavenDependency implements IMavenDependency { + + private static final IDependencyFormatter sDependencyFormatter = new SimpleDependencyFormatter(); + 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 index 89d67d89..e011db63 100644 --- 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 @@ -48,6 +48,15 @@ public IMavenDependency adapt(DependencyResult dependencyResult) { } } + @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(); @@ -55,10 +64,6 @@ private IMavenDependency adapt(ResolvedDependencyResult resolvedDependencyResult return null; } - final String group = selectedModuleVersion.getGroup(); - final String name = selectedModuleVersion.getName(); - final String version = selectedModuleVersion.getVersion(); - - return new MavenDependency(group, name, version); + return adapt(selectedModuleVersion); } } diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index 0690bf40..f2899ae6 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -37,6 +37,11 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import lombok.NonNull; @@ -44,39 +49,66 @@ public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { private static final String CG_MANIFEST_FILE_NAME = "cgmanifest.json"; - final CgManifest mCgManifest = new CgManifest(); - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final JsonParser JSON_PARSER = new JsonParser(); private final IDependencyComponentAdapter mDependencyComponentAdapter = new MavenComponentDependencyAdapter(); + private final Map mRegisteredMavenDependencies = new HashMap<>(); + public CGManifestDependencyRenderer(DependencyRendererSettings dependencyRendererSettings) { super(dependencyRendererSettings); } @Override public void render(@NonNull GradleDependency gradleDependency) { - final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt( - gradleDependency.getMavenDependency() - ); - mCgManifest.addRegistration(new Registration( - mavenComponent, - gradleDependency.getDependencyType() == DependencyType.DEVELOPMENT - )); + // we could do something here...but let's just take the final result from the complete + // method } @Override - public void completeProject(Project project) { - super.completeProject(project); - final String cgManifestJson = GSON.toJson(mCgManifest); + public void complete(@NonNull Collection gradleDependencies) { + final CgManifest cgManifest = createCgManifest(gradleDependencies); + + final String cgManifestJson = GSON.toJson(cgManifest); final JsonElement cgManifestJsonElement = JSON_PARSER.parse(cgManifestJson); final String cgManifestPrettyJson = GSON.toJson(cgManifestJsonElement); System.out.println(cgManifestPrettyJson); dumpToCgManifestJsonFile(cgManifestPrettyJson); } + @Override + public void completeProject(Project project) { + super.completeProject(project); + } + + private CgManifest createCgManifest(@NonNull final Collection gradleDependencies) { + final CgManifest cgManifest = new CgManifest(); + + for (final GradleDependency gradleDependency : gradleDependencies) { + final IMavenDependency mavenDependency = gradleDependency.getMavenDependency(); + final DependencyType dependencyType = gradleDependency.getDependencyType(); + final Set rootDeps = gradleDependency.getDependencyRoots(); + + final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt( + mavenDependency + ); + + final Set rootComponents = new HashSet<>(); + + rootDeps.iterator().forEachRemaining(mavenDep -> rootComponents.add(mDependencyComponentAdapter.adapt(mavenDep))); + + cgManifest.addRegistration(new Registration( + mavenComponent, + dependencyType == DependencyType.DEVELOPMENT, + rootComponents + )); + } + + return cgManifest; + } + private void dumpToCgManifestJsonFile(final String text) { try { final FileWriter fileWriter = new FileWriter(CG_MANIFEST_FILE_NAME); 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 index d56323de..4adaa20d 100644 --- 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 @@ -24,7 +24,6 @@ import com.google.gson.annotations.SerializedName; -import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -42,7 +41,7 @@ public void addRegistration(@NonNull final Registration registration) { } public Set getRegistrations() { - return Collections.unmodifiableSet(mRegistrations); + return mRegistrations; } private static class SerializedNames { 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 index d8b8a4e7..59655a94 100644 --- 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 @@ -27,9 +27,11 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; +import lombok.experimental.Accessors; @EqualsAndHashCode(callSuper = true) @Getter +@Accessors(prefix = "m") public class MavenComponent extends Component { private static final String MAVEN_COMPONENT_TYPE_NAME = "Maven"; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java index 0c32482d..a7d14733 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java @@ -33,7 +33,6 @@ public MavenComponent adapt(IMavenDependency dependency) { dependency.getVersion() ); - final MavenComponent mavenComponent = new MavenComponent(mavenComponentInfo); - return mavenComponent; + return new MavenComponent(mavenComponentInfo); } } 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 index b488cd84..dd1d45ce 100644 --- 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 @@ -24,11 +24,17 @@ import com.google.gson.annotations.SerializedName; +import java.util.Set; + import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.experimental.Accessors; -@EqualsAndHashCode +@EqualsAndHashCode() @AllArgsConstructor +@Getter +@Accessors(prefix = "m") public class Registration { @SerializedName(SerializedNames.COMPONENT) @@ -37,8 +43,12 @@ public class Registration { @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"; } } From 4a0b3f245a7b897eef3afbc450c6a9943d665476 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Tue, 3 Aug 2021 18:16:42 -0700 Subject: [PATCH 08/11] Add build extension properties for dependency rendering --- .../identity/buildsystem/BuildPlugin.java | 16 ++++++------- .../rendering/AbstractDependencyRenderer.java | 5 ++-- .../rendering/ConsoleDependencyRenderer.java | 5 +++- .../CGManifestDependencyRenderer.java | 14 ++++++----- .../settings/DependencyRendererSettings.java | 5 ++++ .../DependencyRendererSettingsAdapter.java | 23 ++++++++++++++++++- .../DependencyRendererSettingsExtension.java | 5 ++++ 7 files changed, 55 insertions(+), 18 deletions(-) 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 631920e4..e3d593b3 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 @@ -45,9 +45,6 @@ public class BuildPlugin implements Plugin { private final static String JAVA_SOURCE_COMPATIBILITY_PROPERTY = "sourceCompatibility"; private final static String JAVA_TARGET_COMPATIBILITY_PROPERTY = "targetCompatibility"; - private final IDependencyRendererSettingsAdapter mDependencyRendererSettingsAdapter = - new DependencyRendererSettingsAdapter(); - @Override public void apply(final Project project) { @@ -57,15 +54,18 @@ public void apply(final Project project) { final DependencyRendererSettingsExtension dependencyRendererSettingsExtension = project.getExtensions().create("dependencyRendering", DependencyRendererSettingsExtension.class); - project.afterEvaluate(project1 -> { + project.afterEvaluate(evaluatedProject -> { if (config.getDesugar().get()) { - project1.getLogger().warn("DESUGARING ENABLED"); - applyDesugaringToAndroidProject(project1); - applyJava8ToJavaProject(project1); + evaluatedProject.getLogger().warn("DESUGARING ENABLED"); + applyDesugaringToAndroidProject(evaluatedProject); + applyJava8ToJavaProject(evaluatedProject); } else { - project1.getLogger().warn("DESUGARING DISABLED"); + evaluatedProject.getLogger().warn("DESUGARING DISABLED"); } + final IDependencyRendererSettingsAdapter mDependencyRendererSettingsAdapter = + new DependencyRendererSettingsAdapter(evaluatedProject); + final DependencyRendererSettings dependencyRendererSettings = mDependencyRendererSettingsAdapter.adapt(dependencyRendererSettingsExtension); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java index fe4f9f6e..3ef30a46 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java @@ -60,7 +60,8 @@ public abstract class AbstractDependencyRenderer extends TextReportRenderer impl public abstract void render(@NonNull final GradleDependency gradleDependency); - public abstract void complete(@NonNull final Collection gradleDependencies); + public abstract void complete(@NonNull final Project project, + @NonNull final Collection gradleDependencies); private final Map mRenderedDepMap = new HashMap<>(); @@ -72,7 +73,7 @@ public void startConfiguration(Configuration configuration) { @Override public void completeProject(Project project) { - complete(mRenderedDepMap.values()); + complete(project, mRenderedDepMap.values()); } diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java index 0d747afe..1acd33a3 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java @@ -24,6 +24,8 @@ import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +import org.gradle.api.Project; + import java.util.Collection; import lombok.NonNull; @@ -44,7 +46,8 @@ public void render(@NonNull GradleDependency gradleDependency) { } @Override - public void complete(@NonNull Collection gradleDependencies) { + public void complete(@NonNull final Project project, + @NonNull Collection gradleDependencies) { // don't do anything System.out.println("Rendering all now.."); gradleDependencies.iterator().forEachRemaining(gradleDependency -> diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index f2899ae6..6b7f557c 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -34,6 +34,7 @@ import org.gradle.api.Project; +import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; @@ -55,8 +56,6 @@ public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { private final IDependencyComponentAdapter mDependencyComponentAdapter = new MavenComponentDependencyAdapter(); - private final Map mRegisteredMavenDependencies = new HashMap<>(); - public CGManifestDependencyRenderer(DependencyRendererSettings dependencyRendererSettings) { super(dependencyRendererSettings); } @@ -68,14 +67,15 @@ public void render(@NonNull GradleDependency gradleDependency) { } @Override - public void complete(@NonNull Collection gradleDependencies) { + public void complete(@NonNull final Project project, + @NonNull Collection gradleDependencies) { final CgManifest cgManifest = createCgManifest(gradleDependencies); final String cgManifestJson = GSON.toJson(cgManifest); final JsonElement cgManifestJsonElement = JSON_PARSER.parse(cgManifestJson); final String cgManifestPrettyJson = GSON.toJson(cgManifestJsonElement); System.out.println(cgManifestPrettyJson); - dumpToCgManifestJsonFile(cgManifestPrettyJson); + dumpToCgManifestJsonFile(project.getBuildDir(), cgManifestPrettyJson); } @Override @@ -109,9 +109,11 @@ private CgManifest createCgManifest(@NonNull final Collection return cgManifest; } - private void dumpToCgManifestJsonFile(final String text) { + private void dumpToCgManifestJsonFile(@NonNull final File rootDir, @NonNull final String text) { try { - final FileWriter fileWriter = new FileWriter(CG_MANIFEST_FILE_NAME); + 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(); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java index c89c49fd..f4f36f25 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java @@ -22,6 +22,8 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering.settings; +import java.io.File; + import lombok.Builder; import lombok.Getter; import lombok.experimental.Accessors; @@ -30,9 +32,12 @@ @Getter @Accessors(prefix = "m") public class DependencyRendererSettings { + @Builder.Default private final boolean mRenderProjectDependency = false; @Builder.Default private final boolean mRenderTransitiveDependencies = true; + + private final File mCgManifestReportDirectory; } 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 index e7b7f6b4..1a77d990 100644 --- 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 @@ -22,9 +22,18 @@ // 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 lombok.AllArgsConstructor; + +@AllArgsConstructor public class DependencyRendererSettingsAdapter implements IDependencyRendererSettingsAdapter { + + private final Project mProject; + @Override public DependencyRendererSettings adapt(DependencyRendererSettingsExtension extension) { final DependencyRendererSettings.DependencyRendererSettingsBuilder builder = @@ -34,11 +43,23 @@ public DependencyRendererSettings adapt(DependencyRendererSettingsExtension exte return builder.build(); } - Property renderProjectDependency = extension.getRenderProjectDependency(); + 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 { + 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 index e1df4475..b038cc34 100644 --- 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 @@ -24,8 +24,13 @@ import org.gradle.api.provider.Property; +import java.io.File; + public abstract class DependencyRendererSettingsExtension { abstract public Property getRenderProjectDependency(); + abstract public Property getRenderTransitiveDependencies(); + + abstract public Property getCgManifestReportDirectory(); } From 1bdaa560b400a572b8cea8f4819363ce000ec4a4 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Tue, 3 Aug 2021 18:32:12 -0700 Subject: [PATCH 09/11] Fix writing cg manifest report to provided directory --- .../buildsystem/rendering/AbstractDependencyRenderer.java | 2 +- .../rendering/cgmanifest/CGManifestDependencyRenderer.java | 6 +++--- .../rendering/settings/DependencyRendererSettings.java | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java index 3ef30a46..26675f72 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java @@ -52,7 +52,7 @@ @Accessors(prefix = "m") public abstract class AbstractDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { - private final DependencyRendererSettings mDependencyRendererSettings; + protected final DependencyRendererSettings mDependencyRendererSettings; private static final IMavenDependencyAdapter sMavenDependencyAdapter = new MavenDependencyAdapter(); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java index 6b7f557c..0a8d4095 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java @@ -39,9 +39,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; import lombok.NonNull; @@ -75,7 +73,9 @@ public void complete(@NonNull final Project project, final JsonElement cgManifestJsonElement = JSON_PARSER.parse(cgManifestJson); final String cgManifestPrettyJson = GSON.toJson(cgManifestJsonElement); System.out.println(cgManifestPrettyJson); - dumpToCgManifestJsonFile(project.getBuildDir(), cgManifestPrettyJson); + dumpToCgManifestJsonFile( + mDependencyRendererSettings.getCgManifestReportDirectory(), cgManifestPrettyJson + ); } @Override diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java index f4f36f25..6b69efbd 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java @@ -26,6 +26,7 @@ import lombok.Builder; import lombok.Getter; +import lombok.NonNull; import lombok.experimental.Accessors; @Builder @@ -39,5 +40,6 @@ public class DependencyRendererSettings { @Builder.Default private final boolean mRenderTransitiveDependencies = true; + @NonNull private final File mCgManifestReportDirectory; } From 407e6d025ef90e2ff2c1dd046f8ec31538517810 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Wed, 4 Aug 2021 17:56:35 -0700 Subject: [PATCH 10/11] Add javadoc and comments to build plugin dep rendering work --- .../identity/buildsystem/BuildPlugin.java | 22 ++-- ... => AbstractGradleDependencyRenderer.java} | 116 ++++++++++++++++-- ...a => ConsoleGradleDependencyRenderer.java} | 22 ++-- .../buildsystem/rendering/DependencyType.java | 3 + ...dapter.java => DependencyTypeAdapter.java} | 12 +- .../rendering/GradleDependency.java | 14 +++ ...apter.java => IDependencyTypeAdapter.java} | 12 +- .../rendering/IMavenDependency.java | 3 + .../rendering/IMavenDependencyAdapter.java | 22 ++++ ...er.java => IMavenDependencyFormatter.java} | 11 +- .../rendering/MavenDependency.java | 5 +- .../rendering/MavenDependencyAdapter.java | 11 +- ...va => SimpleMavenDependencyFormatter.java} | 8 +- ...> CGManifestGradleDependencyRenderer.java} | 43 +++++-- .../rendering/cgmanifest/CgManifest.java | 5 + .../rendering/cgmanifest/Component.java | 5 + ...encyAdapter.java => ComponentAdapter.java} | 11 +- ...entAdapter.java => IComponentAdapter.java} | 14 ++- .../cgmanifest/IMavenComponentInfo.java | 32 ----- .../rendering/cgmanifest/MavenComponent.java | 6 + .../cgmanifest/MavenComponentInfo.java | 7 +- .../rendering/cgmanifest/Registration.java | 5 + .../DependencyRendererSettingsAdapter.java | 12 +- .../DependencyRendererSettingsExtension.java | 24 ++++ ... => GradleDependencyRendererSettings.java} | 17 ++- .../IDependencyRendererSettingsAdapter.java | 14 ++- 26 files changed, 372 insertions(+), 84 deletions(-) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{AbstractDependencyRenderer.java => AbstractGradleDependencyRenderer.java} (52%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{ConsoleDependencyRenderer.java => ConsoleGradleDependencyRenderer.java} (66%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{ConfigurationAdapter.java => DependencyTypeAdapter.java} (80%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{IConfigurationAdapter.java => IDependencyTypeAdapter.java} (77%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{IDependencyFormatter.java => IMavenDependencyFormatter.java} (79%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/{SimpleDependencyFormatter.java => SimpleMavenDependencyFormatter.java} (86%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/{CGManifestDependencyRenderer.java => CGManifestGradleDependencyRenderer.java} (68%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/{MavenComponentDependencyAdapter.java => ComponentAdapter.java} (84%) rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/{IDependencyComponentAdapter.java => IComponentAdapter.java} (73%) delete mode 100644 plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java rename plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/{DependencyRendererSettings.java => GradleDependencyRendererSettings.java} (72%) 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 e3d593b3..f5b23472 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,13 +23,13 @@ package com.microsoft.identity.buildsystem; import com.android.build.gradle.LibraryExtension; -import com.microsoft.identity.buildsystem.rendering.ConsoleDependencyRenderer; -import com.microsoft.identity.buildsystem.rendering.IDependencyFormatter; -import com.microsoft.identity.buildsystem.rendering.SimpleDependencyFormatter; -import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestDependencyRenderer; -import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +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 org.gradle.api.JavaVersion; @@ -66,17 +66,19 @@ public void apply(final Project project) { final IDependencyRendererSettingsAdapter mDependencyRendererSettingsAdapter = new DependencyRendererSettingsAdapter(evaluatedProject); - final DependencyRendererSettings dependencyRendererSettings = + final GradleDependencyRendererSettings gradleDependencyRendererSettings = mDependencyRendererSettingsAdapter.adapt(dependencyRendererSettingsExtension); + // generate gradle task to print dependencies to console final DependencyReportTask consoleTask = project.getTasks().create("printDependenciesToConsole", DependencyReportTask.class); - final IDependencyFormatter dependencyFormatter = new SimpleDependencyFormatter(); - consoleTask.setRenderer(new ConsoleDependencyRenderer( - dependencyRendererSettings, dependencyFormatter + 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 CGManifestDependencyRenderer(dependencyRendererSettings)); + cgManifestTask.setRenderer(new CGManifestGradleDependencyRenderer(gradleDependencyRendererSettings)); }); SpotBugs.applySpotBugsPlugin(project); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java similarity index 52% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java index 26675f72..0c59c8a7 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java @@ -22,7 +22,7 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -48,41 +48,77 @@ 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 AbstractDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { +public abstract class AbstractGradleDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { - protected final DependencyRendererSettings mDependencyRendererSettings; + /** + * 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 IConfigurationAdapter sConfigurationAdapter = new ConfigurationAdapter(); + 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) { - System.out.println("Starting configuration: " + configuration.getName()); // 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 (mDependencyRendererSettings.isRenderTransitiveDependencies() && canBeResolved(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); } @@ -93,6 +129,12 @@ 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( @@ -100,27 +142,48 @@ private void renderDependencySet(@NonNull final Configuration configuration, ); } + /** + * 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 (rootResult.getId() instanceof ProjectComponentIdentifier && !mDependencyRendererSettings.isRenderProjectDependency()) { + // 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)) { @@ -128,46 +191,83 @@ private void renderDependency(@NonNull final Configuration configuration, } } + /** + * 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) || - mDependencyRendererSettings.isRenderProjectDependency(); + 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/ConsoleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java similarity index 66% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java index 1acd33a3..ab5f8656 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java @@ -22,7 +22,7 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettings; +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; import org.gradle.api.Project; @@ -30,24 +30,28 @@ import lombok.NonNull; -public class ConsoleDependencyRenderer extends AbstractDependencyRenderer { +/** + * 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 IDependencyFormatter mDependencyFormatter; + private final IMavenDependencyFormatter mDependencyFormatter; - public ConsoleDependencyRenderer(@NonNull final DependencyRendererSettings dependencyRendererSettings, - @NonNull final IDependencyFormatter dependencyFormatter) { - super(dependencyRendererSettings); + public ConsoleGradleDependencyRenderer(@NonNull final GradleDependencyRendererSettings gradleDependencyRendererSettings, + @NonNull final IMavenDependencyFormatter dependencyFormatter) { + super(gradleDependencyRendererSettings); mDependencyFormatter = dependencyFormatter; } @Override - public void render(@NonNull GradleDependency gradleDependency) { + public void render(@NonNull final GradleDependency gradleDependency) { render(mDependencyFormatter.formatDependency(gradleDependency.getMavenDependency())); } @Override public void complete(@NonNull final Project project, - @NonNull Collection gradleDependencies) { + @NonNull final Collection gradleDependencies) { // don't do anything System.out.println("Rendering all now.."); gradleDependencies.iterator().forEachRemaining(gradleDependency -> @@ -55,7 +59,7 @@ public void complete(@NonNull final Project project, ); } - private void render(String formattedDependency) { + 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 index 0eb91492..b812baa3 100644 --- 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 @@ -22,6 +22,9 @@ // 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/ConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java similarity index 80% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java index 5c41a947..6bf7f348 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConfigurationAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java @@ -26,7 +26,10 @@ import lombok.NonNull; -public class ConfigurationAdapter implements IConfigurationAdapter { +/** + * An implementation of the {@link IDependencyTypeAdapter}. + */ +public class DependencyTypeAdapter implements IDependencyTypeAdapter { @Override public DependencyType adapt(Configuration configuration) { if (isRuntimeConfiguration(configuration.getName())) { @@ -36,6 +39,13 @@ public DependencyType adapt(Configuration configuration) { } } + /** + * 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": 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 index bb754e6c..3dbd97a3 100644 --- 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 @@ -30,6 +30,9 @@ import lombok.NonNull; import lombok.experimental.Accessors; +/** + * Represents a Gradle Dependency. + */ @AllArgsConstructor @Getter @Accessors(prefix = "m") @@ -39,10 +42,21 @@ public class GradleDependency { 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; } diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java similarity index 77% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java index 89d091bf..99e15647 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IConfigurationAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java @@ -24,7 +24,17 @@ import org.gradle.api.artifacts.Configuration; -public interface IConfigurationAdapter { +/** + * 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 index 9cb1ef10..0fb39a72 100644 --- 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 @@ -22,6 +22,9 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; +/** + * Describes a maven dependency. + */ public interface IMavenDependency { /** 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 index 3f29e945..a3b296ab 100644 --- 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 @@ -26,11 +26,33 @@ 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/IDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java similarity index 79% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java index 4005f409..79ca53be 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java @@ -22,7 +22,16 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -public interface IDependencyFormatter { +/** + * 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 index 34c333ae..18ac36f6 100644 --- 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 @@ -27,13 +27,16 @@ 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 IDependencyFormatter sDependencyFormatter = new SimpleDependencyFormatter(); + private static final IMavenDependencyFormatter sDependencyFormatter = new SimpleMavenDependencyFormatter(); private final String mGroup; private final String mName; 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 index e011db63..b5080628 100644 --- 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 @@ -27,8 +27,13 @@ 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) { @@ -39,8 +44,9 @@ public IMavenDependency adapt(@NonNull final Dependency dependency) { return new MavenDependency(group, name, version); } + @Nullable @Override - public IMavenDependency adapt(DependencyResult dependencyResult) { + public IMavenDependency adapt(@NonNull final DependencyResult dependencyResult) { if (dependencyResult instanceof ResolvedDependencyResult) { return adapt((ResolvedDependencyResult) dependencyResult); } else { @@ -58,7 +64,8 @@ public IMavenDependency adapt(@NonNull final ModuleVersionIdentifier moduleVersi } private IMavenDependency adapt(ResolvedDependencyResult resolvedDependencyResult) { - final ModuleVersionIdentifier selectedModuleVersion = resolvedDependencyResult.getSelected().getModuleVersion(); + final ModuleVersionIdentifier selectedModuleVersion = + resolvedDependencyResult.getSelected().getModuleVersion(); if (selectedModuleVersion == null) { return null; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java similarity index 86% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java index 2fc573fb..367009e2 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleDependencyFormatter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java @@ -22,7 +22,13 @@ // THE SOFTWARE. package com.microsoft.identity.buildsystem.rendering; -public class SimpleDependencyFormatter implements IDependencyFormatter { +/** + * 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 = ":"; diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java similarity index 68% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java index 0a8d4095..0e93dab4 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestDependencyRenderer.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java @@ -26,11 +26,11 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import com.microsoft.identity.buildsystem.rendering.AbstractDependencyRenderer; +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.DependencyRendererSettings; +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; import org.gradle.api.Project; @@ -44,18 +44,24 @@ import lombok.NonNull; -public class CGManifestDependencyRenderer extends AbstractDependencyRenderer { +/** + * 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 IDependencyComponentAdapter mDependencyComponentAdapter = - new MavenComponentDependencyAdapter(); + private final IComponentAdapter mDependencyComponentAdapter = new ComponentAdapter(); - public CGManifestDependencyRenderer(DependencyRendererSettings dependencyRendererSettings) { - super(dependencyRendererSettings); + public CGManifestGradleDependencyRenderer(GradleDependencyRendererSettings gradleDependencyRendererSettings) { + super(gradleDependencyRendererSettings); } @Override @@ -67,14 +73,24 @@ public void render(@NonNull GradleDependency gradleDependency) { @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( - mDependencyRendererSettings.getCgManifestReportDirectory(), cgManifestPrettyJson + mGradleDependencyRendererSettings.getCgManifestReportDirectory(), cgManifestPrettyJson ); } @@ -86,19 +102,30 @@ public void completeProject(Project 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, 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 index 4adaa20d..f6f02c13 100644 --- 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 @@ -30,6 +30,11 @@ 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 { 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 index 541ac61b..4d540db2 100644 --- 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 @@ -27,6 +27,11 @@ 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 { diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java similarity index 84% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java index a7d14733..71a9fb01 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentDependencyAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java @@ -24,9 +24,16 @@ import com.microsoft.identity.buildsystem.rendering.IMavenDependency; -public class MavenComponentDependencyAdapter implements IDependencyComponentAdapter { +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(IMavenDependency dependency) { + public MavenComponent adapt(@NonNull final IMavenDependency dependency) { final MavenComponentInfo mavenComponentInfo = new MavenComponentInfo( dependency.getGroup(), dependency.getName(), diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java similarity index 73% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java index f382243b..b12d9d1c 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IDependencyComponentAdapter.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java @@ -24,7 +24,17 @@ import com.microsoft.identity.buildsystem.rendering.IMavenDependency; -public interface IDependencyComponentAdapter { +/** + * Converts an internal dependency into a {@link Component}. + */ +public interface IComponentAdapter { - T adapt(IMavenDependency dependency); + /** + * 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/IMavenComponentInfo.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java deleted file mode 100644 index 46889f02..00000000 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IMavenComponentInfo.java +++ /dev/null @@ -1,32 +0,0 @@ -// 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; - -public interface IMavenComponentInfo { - String getGroupId(); - - String getArtifactId(); - - String getVersion(); - -} 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 index 59655a94..a92b4603 100644 --- 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 @@ -29,6 +29,12 @@ 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") 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 index 22b66836..93131752 100644 --- 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 @@ -28,10 +28,15 @@ 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 implements IMavenComponentInfo { +public class MavenComponentInfo { @SerializedName(SerializedNames.GROUP_ID) private final String mGroupId; 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 index dd1d45ce..40ccca39 100644 --- 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 @@ -31,6 +31,11 @@ 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 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 index 1a77d990..b85cee4e 100644 --- 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 @@ -27,17 +27,22 @@ 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 DependencyRendererSettings adapt(DependencyRendererSettingsExtension extension) { - final DependencyRendererSettings.DependencyRendererSettingsBuilder builder = - DependencyRendererSettings.builder(); + public GradleDependencyRendererSettings adapt(@Nullable final DependencyRendererSettingsExtension extension) { + final GradleDependencyRendererSettings.GradleDependencyRendererSettingsBuilder builder = + GradleDependencyRendererSettings.builder(); if (extension == null) { return builder.build(); @@ -57,6 +62,7 @@ public DependencyRendererSettings adapt(DependencyRendererSettingsExtension exte 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()); } 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 index b038cc34..47e3dbf2 100644 --- 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 @@ -26,11 +26,35 @@ 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/DependencyRendererSettings.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java similarity index 72% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java index 6b69efbd..c5459316 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettings.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java @@ -29,17 +29,32 @@ 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 DependencyRendererSettings { +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 index a1e00b53..617d89f3 100644 --- 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 @@ -22,9 +22,21 @@ // 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 { - DependencyRendererSettings adapt( + /** + * 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 ); From 40a5e3f0771bf780b67f475b6e72e2101b659670 Mon Sep 17 00:00:00 2001 From: Shahzaib Date: Wed, 10 Nov 2021 16:39:03 -0800 Subject: [PATCH 11/11] Fix issue caused by merge --- plugins/buildsystem/build.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 {