-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle java source/target defined at extension level
- Loading branch information
Arthur McGibbon
committed
Aug 27, 2024
1 parent
395b977
commit 755fdef
Showing
9 changed files
with
175 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
plugin/src/main/java/com/microsoft/java/bs/gradle/plugin/utils/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
package com.microsoft.java.bs.gradle.plugin.utils; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* Helper functions. | ||
*/ | ||
public class Utils { | ||
|
||
/** | ||
* Invoke a method by reflection and pass back any exceptions thrown. | ||
* Method takes no parameters. | ||
* | ||
* @param <A> expected return type | ||
* @param object instance to invoke method on. | ||
* @param methodName name of method to invoke. | ||
* @return result of method called. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <A> A invokeMethod(Object object, String methodName) | ||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
return (A) object.getClass().getMethod(methodName).invoke(object); | ||
} | ||
|
||
/** | ||
* Invoke a method by reflection and return null if method cannot be called. | ||
* Method takes no parameters. | ||
* | ||
* @param <A> expected return type | ||
* @param object instance to invoke method on. | ||
* @param methodName name of method to invoke. | ||
* @return result of method called. | ||
*/ | ||
public static <A> A invokeMethodIgnoreFail(Object object, String methodName) { | ||
try { | ||
return invokeMethod(object, methodName); | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
java { | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
sourceCompatibility = JavaVersion.VERSION_1_9 | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.compilerArgs.addAll(['--release', '8']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'java-source-target' |