diff --git a/plugins/buildsystem/build.gradle b/plugins/buildsystem/build.gradle index 3c62740d..ccd2ced0 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.2.0' pluginBundle { 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..c98c2096 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,39 +23,70 @@ package com.microsoft.identity.buildsystem; import com.android.build.gradle.LibraryExtension; +import com.microsoft.identity.buildsystem.constants.Constants; +import com.microsoft.identity.buildsystem.extensions.AndroidBuildExtension; +import com.microsoft.identity.buildsystem.extensions.BuildPluginExtension; +import com.microsoft.identity.buildsystem.extensions.JavaBuildExtension; +import com.microsoft.identity.buildsystem.extensions.appliers.AndroidBuildExtensionApplier; +import com.microsoft.identity.buildsystem.extensions.appliers.JavaBuildExtensionApplier; +import com.microsoft.identity.buildsystem.spotbugs.SpotBugs; + import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.provider.Property; -public class BuildPlugin implements Plugin { - - private final static String ANDROID_LIBRARY_PLUGIN_ID = "com.android.library"; - private final static String JAVA_LIBRARY_PLUGIN_ID = "java-library"; +import static com.microsoft.identity.buildsystem.constants.Constants.PluginIdentifiers.ANDROID_LIBRARY_PLUGIN_ID; +import static com.microsoft.identity.buildsystem.constants.Constants.PluginIdentifiers.JAVA_LIBRARY_PLUGIN_ID; +import static com.microsoft.identity.buildsystem.constants.Constants.ProjectProperties.JAVA_SOURCE_COMPATIBILITY_PROPERTY; +import static com.microsoft.identity.buildsystem.constants.Constants.ProjectProperties.JAVA_TARGET_COMPATIBILITY_PROPERTY; - private final static String JAVA_SOURCE_COMPATIBILITY_PROPERTY = "sourceCompatibility"; - private final static String JAVA_TARGET_COMPATIBILITY_PROPERTY = "targetCompatibility"; +public class BuildPlugin implements Plugin { @Override public void apply(final Project project) { + project.getPluginManager().withPlugin(ANDROID_LIBRARY_PLUGIN_ID, appliedPlugin -> { + final AndroidBuildExtension androidConfig = project.getExtensions() + .create(Constants.ExtensionNames.ANDROID_BUILD_EXTENSION, AndroidBuildExtension.class); + new AndroidBuildExtensionApplier().applyBuildExtensionProperties(project, androidConfig); + }); + + project.getPluginManager().withPlugin(JAVA_LIBRARY_PLUGIN_ID, appliedPlugin -> { + final JavaBuildExtension javaConfig = project.getExtensions() + .create(Constants.ExtensionNames.JAVA_BUILD_EXTENSION, JavaBuildExtension.class); + + new JavaBuildExtensionApplier().applyBuildExtensionProperties(project, javaConfig); + }); + + applyBuildSystemConfig(project); + + SpotBugs.applySpotBugsPlugin(project); + } + + @Deprecated + private void applyBuildSystemConfig(final Project project) { final BuildPluginExtension config = project.getExtensions() .create("buildSystem", BuildPluginExtension.class); project.afterEvaluate(project1 -> { - if(config.getDesugar().get()) { - project1.getLogger().warn("DESUGARING ENABLED"); - applyDesugaringToAndroidProject(project1); - applyJava8ToJavaProject(project1); - }else{ - project1.getLogger().warn("DESUGARING DISABLED"); + final Property desugarProperty = config.getDesugar(); + + if (desugarProperty != null && desugarProperty.isPresent()) { + final boolean desugar = desugarProperty.get(); + if (desugar) { + project1.getLogger().warn("DESUGARING ENABLED"); + applyDesugaringToAndroidProject(project1); + applyJava8ToJavaProject(project1); + } else { + project1.getLogger().warn("DESUGARING DISABLED"); + } } }); - - SpotBugs.applySpotBugsPlugin(project); } - private void applyDesugaringToAndroidProject(final Project project){ - + @Deprecated + private void applyDesugaringToAndroidProject(final Project project) { project.getPluginManager().withPlugin(ANDROID_LIBRARY_PLUGIN_ID, appliedPlugin -> { LibraryExtension libraryExtension = project.getExtensions().findByType(LibraryExtension.class); libraryExtension.getCompileOptions().setSourceCompatibility(JavaVersion.VERSION_1_8); @@ -65,6 +96,7 @@ private void applyDesugaringToAndroidProject(final Project project){ } + @Deprecated private void applyJava8ToJavaProject(final Project project) { project.getPluginManager().withPlugin(JAVA_LIBRARY_PLUGIN_ID, appliedPlugin -> { project.setProperty(JAVA_SOURCE_COMPATIBILITY_PROPERTY, JavaVersion.VERSION_1_8); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/Constants.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/Constants.java new file mode 100644 index 00000000..92460998 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/Constants.java @@ -0,0 +1,42 @@ +// 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.constants; + +public class Constants { + + public static class PluginIdentifiers { + public final static String ANDROID_LIBRARY_PLUGIN_ID = "com.android.library"; + public final static String JAVA_LIBRARY_PLUGIN_ID = "java-library"; + public final static String BUILD_SYSTEM_PLUGIN_ID = "com.microsoft.identity.buildsystem"; + } + + public static class ProjectProperties { + public final static String JAVA_SOURCE_COMPATIBILITY_PROPERTY = "sourceCompatibility"; + public final static String JAVA_TARGET_COMPATIBILITY_PROPERTY = "targetCompatibility"; + } + + public static class ExtensionNames { + public final static String JAVA_BUILD_EXTENSION = "javaBuild"; + public final static String ANDROID_BUILD_EXTENSION = "androidBuild"; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/ProjectType.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/ProjectType.java new file mode 100644 index 00000000..dcdffc77 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/constants/ProjectType.java @@ -0,0 +1,28 @@ +// 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.constants; + +public enum ProjectType { + JAVA, + ANDROID; +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/AndroidBuildExtension.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/AndroidBuildExtension.java new file mode 100644 index 00000000..56831146 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/AndroidBuildExtension.java @@ -0,0 +1,30 @@ +// 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.extensions; + +import org.gradle.api.provider.Property; + +public abstract class AndroidBuildExtension extends JavaBuildExtension { + + abstract public Property getDesugar(); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPluginExtension.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/BuildPluginExtension.java similarity index 94% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPluginExtension.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/BuildPluginExtension.java index e0c3e8fa..74519ed4 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPluginExtension.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/BuildPluginExtension.java @@ -1,32 +1,33 @@ -// 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; - -import org.gradle.api.provider.Property; - -abstract public class BuildPluginExtension { - - abstract public Property getMessage(); - abstract public Property getDesugar(); - -} +// 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.extensions; + +import org.gradle.api.provider.Property; + +@Deprecated +abstract public class BuildPluginExtension { + + abstract public Property getMessage(); + abstract public Property getDesugar(); + +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/JavaBuildExtension.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/JavaBuildExtension.java new file mode 100644 index 00000000..d7fc498b --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/JavaBuildExtension.java @@ -0,0 +1,32 @@ +// 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.extensions; + +import org.gradle.api.JavaVersion; +import org.gradle.api.provider.Property; + +public abstract class JavaBuildExtension { + + abstract public Property getMessage(); + abstract public Property getJavaVersion(); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AbstractJavaBuildExtensionApplier.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AbstractJavaBuildExtensionApplier.java new file mode 100644 index 00000000..71ed40da --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AbstractJavaBuildExtensionApplier.java @@ -0,0 +1,32 @@ +package com.microsoft.identity.buildsystem.extensions.appliers; + +import com.microsoft.identity.buildsystem.constants.ProjectType; +import com.microsoft.identity.buildsystem.extensions.JavaBuildExtension; +import com.microsoft.identity.buildsystem.java.version.setters.JavaVersionSetterFactory; + +import org.gradle.api.JavaVersion; +import org.gradle.api.Project; +import org.gradle.api.provider.Property; + +public abstract class AbstractJavaBuildExtensionApplier implements IBuildExtensionApplier { + + private final ProjectType mProjectType; + + public AbstractJavaBuildExtensionApplier(final ProjectType projectType) { + this.mProjectType = projectType; + } + + @Override + public void applyBuildExtensionProperties(final Project project, final JavaBuildExtension buildExtension) { + project.afterEvaluate(evaluatedProject -> { + final Property javaVersionProperty = buildExtension.getJavaVersion(); + + if (javaVersionProperty != null && javaVersionProperty.isPresent()) { + final JavaVersion javaVersion = javaVersionProperty.get(); + + JavaVersionSetterFactory.INSTANCE.getJavaVersionSetter(mProjectType) + .setJavaVersionOnProject(project, javaVersion); + } + }); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AndroidBuildExtensionApplier.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AndroidBuildExtensionApplier.java new file mode 100644 index 00000000..ddb0c3ea --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/AndroidBuildExtensionApplier.java @@ -0,0 +1,61 @@ +// 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.extensions.appliers; + +import com.android.build.gradle.LibraryExtension; +import com.microsoft.identity.buildsystem.constants.ProjectType; +import com.microsoft.identity.buildsystem.extensions.AndroidBuildExtension; +import com.microsoft.identity.buildsystem.extensions.JavaBuildExtension; + +import org.gradle.api.Project; +import org.gradle.api.provider.Property; + +import static com.microsoft.identity.buildsystem.constants.Constants.PluginIdentifiers.ANDROID_LIBRARY_PLUGIN_ID; + +public class AndroidBuildExtensionApplier extends AbstractJavaBuildExtensionApplier { + + public AndroidBuildExtensionApplier() { + super(ProjectType.ANDROID); + } + + @Override + public void applyBuildExtensionProperties(final Project project, final AndroidBuildExtension buildExtension) { + super.applyBuildExtensionProperties(project, (JavaBuildExtension) buildExtension); + project.afterEvaluate(evaluatedProject -> { + final Property desugarProperty = buildExtension.getDesugar(); + + if (desugarProperty != null && desugarProperty.isPresent()) { + final boolean desugar = desugarProperty.get(); + + applyDesugaringToAndroidProject(project, desugar); + } + }); + } + + private void applyDesugaringToAndroidProject(final Project project, final boolean desugar) { + project.getPluginManager().withPlugin(ANDROID_LIBRARY_PLUGIN_ID, appliedPlugin -> { + LibraryExtension libraryExtension = project.getExtensions().findByType(LibraryExtension.class); + libraryExtension.getCompileOptions().setCoreLibraryDesugaringEnabled(desugar); + }); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/IBuildExtensionApplier.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/IBuildExtensionApplier.java new file mode 100644 index 00000000..63da084c --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/IBuildExtensionApplier.java @@ -0,0 +1,30 @@ +// 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.extensions.appliers; + +import org.gradle.api.Project; + +public interface IBuildExtensionApplier { + + void applyBuildExtensionProperties(Project project, T buildExtension); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/JavaBuildExtensionApplier.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/JavaBuildExtensionApplier.java new file mode 100644 index 00000000..b44af88f --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/extensions/appliers/JavaBuildExtensionApplier.java @@ -0,0 +1,33 @@ +// 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.extensions.appliers; + +import com.microsoft.identity.buildsystem.constants.ProjectType; +import com.microsoft.identity.buildsystem.extensions.JavaBuildExtension; + +public class JavaBuildExtensionApplier extends AbstractJavaBuildExtensionApplier { + + public JavaBuildExtensionApplier() { + super(ProjectType.JAVA); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/AndroidProjectJavaVersionSetter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/AndroidProjectJavaVersionSetter.java new file mode 100644 index 00000000..db2f42bf --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/AndroidProjectJavaVersionSetter.java @@ -0,0 +1,44 @@ +// 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.java.version.setters; + +import com.android.build.gradle.LibraryExtension; + +import org.gradle.api.JavaVersion; +import org.gradle.api.Project; + +import static com.microsoft.identity.buildsystem.constants.Constants.PluginIdentifiers.ANDROID_LIBRARY_PLUGIN_ID; + +public class AndroidProjectJavaVersionSetter implements IProjectJavaVersionSetter { + + @Override + public void setJavaVersionOnProject(final Project project, final JavaVersion javaVersion) { + project.getPluginManager().withPlugin(ANDROID_LIBRARY_PLUGIN_ID, appliedPlugin -> { + final LibraryExtension libraryExtension = project.getExtensions().findByType( + LibraryExtension.class + ); + libraryExtension.getCompileOptions().setSourceCompatibility(javaVersion); + libraryExtension.getCompileOptions().setTargetCompatibility(javaVersion); + }); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/IProjectJavaVersionSetter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/IProjectJavaVersionSetter.java new file mode 100644 index 00000000..0610a50c --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/IProjectJavaVersionSetter.java @@ -0,0 +1,32 @@ +// 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.java.version.setters; + +import org.gradle.api.JavaVersion; +import org.gradle.api.Project; + +public interface IProjectJavaVersionSetter { + + void setJavaVersionOnProject(Project project, JavaVersion javaVersion); + +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaProjectJavaVersionSetter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaProjectJavaVersionSetter.java new file mode 100644 index 00000000..72fd3a2f --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaProjectJavaVersionSetter.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.java.version.setters; + +import org.gradle.api.JavaVersion; +import org.gradle.api.Project; + +import static com.microsoft.identity.buildsystem.constants.Constants.PluginIdentifiers.JAVA_LIBRARY_PLUGIN_ID; +import static com.microsoft.identity.buildsystem.constants.Constants.ProjectProperties.JAVA_SOURCE_COMPATIBILITY_PROPERTY; +import static com.microsoft.identity.buildsystem.constants.Constants.ProjectProperties.JAVA_TARGET_COMPATIBILITY_PROPERTY; + +public class JavaProjectJavaVersionSetter implements IProjectJavaVersionSetter { + + @Override + public void setJavaVersionOnProject(final Project project, final JavaVersion javaVersion) { + project.getPluginManager().withPlugin(JAVA_LIBRARY_PLUGIN_ID, appliedPlugin -> { + project.setProperty(JAVA_SOURCE_COMPATIBILITY_PROPERTY, javaVersion); + project.setProperty(JAVA_TARGET_COMPATIBILITY_PROPERTY, javaVersion); + }); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaVersionSetterFactory.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaVersionSetterFactory.java new file mode 100644 index 00000000..edc4a72c --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/java/version/setters/JavaVersionSetterFactory.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.java.version.setters; + +import com.microsoft.identity.buildsystem.constants.ProjectType; + +public enum JavaVersionSetterFactory { + + INSTANCE; + + public IProjectJavaVersionSetter getJavaVersionSetter(ProjectType projectType) { + if (projectType == ProjectType.ANDROID) { + return new AndroidProjectJavaVersionSetter(); + } else { + return new JavaProjectJavaVersionSetter(); + } + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/SpotBugs.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/spotbugs/SpotBugs.java similarity index 95% rename from plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/SpotBugs.java rename to plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/spotbugs/SpotBugs.java index 0b68b2c2..526f72e1 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/SpotBugs.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/spotbugs/SpotBugs.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -package com.microsoft.identity.buildsystem; +package com.microsoft.identity.buildsystem.spotbugs; import com.github.spotbugs.snom.SpotBugsExtension; import com.github.spotbugs.snom.SpotBugsPlugin; @@ -41,7 +41,7 @@ public final class SpotBugs { * @see Spotbugs gradle plugin * @param project project to apply the Spotbugs plugin */ - static void applySpotBugsPlugin(Project project) { + public static void applySpotBugsPlugin(Project project) { if(!project.getPlugins().hasPlugin(SpotBugsPlugin.class)) { project.getPlugins().apply(SpotBugsPlugin.class); }