Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add separate plugin extensions for java and Android projects #95

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/buildsystem/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.microsoft.identity'
version '0.1.1'
version '0.2.0'


pluginBundle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {

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<Project> {

@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<Boolean> 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> getDesugar();
}
Original file line number Diff line number Diff line change
@@ -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<String> getMessage();
abstract public Property<Boolean> 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<String> getMessage();
abstract public Property<Boolean> getDesugar();

}
Original file line number Diff line number Diff line change
@@ -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<String> getMessage();
abstract public Property<JavaVersion> getJavaVersion();
}
Original file line number Diff line number Diff line change
@@ -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<T extends JavaBuildExtension> implements IBuildExtensionApplier<T> {

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<JavaVersion> javaVersionProperty = buildExtension.getJavaVersion();

if (javaVersionProperty != null && javaVersionProperty.isPresent()) {
final JavaVersion javaVersion = javaVersionProperty.get();

JavaVersionSetterFactory.INSTANCE.getJavaVersionSetter(mProjectType)
.setJavaVersionOnProject(project, javaVersion);
}
});
}
}
Loading