-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove plugin-init.groovy in resources and compile the plugin code wi…
…th groovyc (#221)
- Loading branch information
1 parent
734fec9
commit 1269a86
Showing
6 changed files
with
118 additions
and
151 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
93 changes: 93 additions & 0 deletions
93
src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy
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,93 @@ | ||
/* | ||
* (C) Copyright Uwe Schindler (Generics Policeman) and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package de.thetaphi.forbiddenapis.gradle; | ||
|
||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.plugins.JavaBasePlugin; | ||
import org.gradle.util.GradleVersion; | ||
|
||
/** | ||
* Forbiddenapis Gradle Plugin (requires at least Gradle v3.2) | ||
* @since 2.0 | ||
*/ | ||
public class ForbiddenApisPlugin extends ForbiddenApisPluginBase { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
if (GradleVersion.current().compareTo(MIN_GRADLE_VERSION) < 0) { | ||
throw new GradleException("Forbiddenapis plugin requires at least " + MIN_GRADLE_VERSION + ", running version is " + GradleVersion.current()); | ||
} | ||
|
||
project.plugins.apply(JavaBasePlugin.class); | ||
|
||
// create Extension for defaults: | ||
def extension = project.extensions.create(FORBIDDEN_APIS_EXTENSION_NAME, CheckForbiddenApisExtension.class, project); | ||
|
||
// Create a convenience task for all checks (this does not conflict with extension, as it has higher priority in DSL): | ||
def forbiddenTask = TASK_AVOIDANCE_AVAILABLE ? project.tasks.register(FORBIDDEN_APIS_TASK_NAME) : project.tasks.create(FORBIDDEN_APIS_TASK_NAME) | ||
forbiddenTask.configure { | ||
description = "Runs forbidden-apis checks."; | ||
group = JavaBasePlugin.VERIFICATION_GROUP; | ||
} | ||
|
||
// Gradle is buggy with it's JavaVersion enum: We use majorVersion property before Java 11 (6,7,8,9,10) and for later we use toString() to be future-proof: | ||
Closure targetCompatibilityGetter = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ? | ||
project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion }; | ||
|
||
// Define our tasks (one for each SourceSet): | ||
project.sourceSets.all{ sourceSet -> | ||
String sourceSetTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null); | ||
def sourceSetTask = TASK_AVOIDANCE_AVAILABLE ? project.tasks.register(sourceSetTaskName, CheckForbiddenApis.class) : | ||
project.tasks.create(sourceSetTaskName, CheckForbiddenApis.class); | ||
def templateClassesDirs = project.files(); | ||
def templateClasspath = project.files(); | ||
sourceSetTask.configure { | ||
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes."; | ||
dependsOn(sourceSet.output); | ||
outputs.upToDateWhen { true } | ||
def taskData = internalTaskData() | ||
conventionMapping.with{ | ||
FORBIDDEN_APIS_EXTENSION_PROPS.each{ key -> | ||
map(key, { | ||
def item = taskData[key] | ||
if (item instanceof ConfigurableFileCollection) { | ||
return item.from(extension[key]) | ||
} else if (item instanceof Collection) { | ||
item.addAll(extension[key]) | ||
return item | ||
} | ||
return extension[key] | ||
}) | ||
} | ||
classesDirs = { templateClassesDirs.from(sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : sourceSet.output.classesDir) } | ||
classpath = { templateClasspath.from(sourceSet.compileClasspath) } | ||
targetCompatibility = targetCompatibilityGetter | ||
} | ||
} | ||
forbiddenTask.configure { | ||
dependsOn(sourceSetTask) | ||
} | ||
} | ||
|
||
// Add our task as dependency to chain | ||
def checkTask = TASK_AVOIDANCE_AVAILABLE ? project.tasks.named(JavaBasePlugin.CHECK_TASK_NAME) : project.tasks.getByName(JavaBasePlugin.CHECK_TASK_NAME); | ||
checkTask.configure { it.dependsOn(forbiddenTask) }; | ||
} | ||
|
||
} |
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
77 changes: 0 additions & 77 deletions
77
src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy
This file was deleted.
Oops, something went wrong.