Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package org.elasticsearch.gradle

import groovy.transform.CompileStatic
import org.elasticsearch.gradle.info.BuildParams
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
import org.elasticsearch.gradle.internal.InternalPlugin
import org.elasticsearch.gradle.internal.precommit.InternalPrecommitTasks
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
Expand All @@ -39,6 +42,7 @@ class BuildPlugin implements Plugin<Project> {
void apply(Project project) {
// make sure the global build info plugin is applied to the root project
project.rootProject.pluginManager.apply(GlobalBuildInfoPlugin)
checkExternalInternalPluginUsages(project);

if (project.pluginManager.hasPlugin('elasticsearch.standalone-rest-test')) {
throw new InvalidUserDataException('elasticsearch.standalone-test, '
Expand All @@ -51,7 +55,19 @@ class BuildPlugin implements Plugin<Project> {
project.pluginManager.apply(DependenciesInfoPlugin)
project.pluginManager.apply(DependenciesGraphPlugin)

PrecommitTasks.create(project, true)
BuildParams.withInternalBuild {
InternalPrecommitTasks.create(project, true)
}.orElse {
PrecommitTasks.create(project)
}
}

private static void checkExternalInternalPluginUsages(Project project) {
if (BuildParams.isInternal() == false) {
project.getPlugins().withType(InternalPlugin.class) { InternalPlugin internalPlugin ->
throw new GradleException(internalPlugin.getExternalUseErrorMessage())
}
}
}

static void configureLicenseAndNotice(Project project) {
Expand Down Expand Up @@ -81,4 +97,4 @@ class BuildPlugin implements Plugin<Project> {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.gradle

import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
import org.elasticsearch.gradle.internal.precommit.DependencyLicensesTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.gradle

import org.elasticsearch.gradle.precommit.DependencyLicensesTask
import org.elasticsearch.gradle.internal.precommit.DependencyLicensesTask
import org.elasticsearch.gradle.precommit.LicenseAnalyzer
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 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
* 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
Expand All @@ -16,35 +16,43 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.gradle.precommit

package org.elasticsearch.gradle.internal.precommit

import org.gradle.api.Project
import groovy.transform.CompileStatic
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.elasticsearch.gradle.precommit.ThirdPartyAuditPrecommitPlugin;
import org.gradle.api.Project;

/**
* Validation tasks which should be run before committing. These run before tests.
*/
class PrecommitTasks {
* Internal precommit plugins that adds elasticsearch project specific
* checks to the common precommit plugin.
* */

/** Adds a precommit task, which depends on non-test verification tasks. */
@CompileStatic
class InternalPrecommitTasks {

/**
* Adds a precommit task, which depends on non-test verification tasks.
*/
static void create(Project project, boolean includeDependencyLicenses) {
PrecommitTasks.create(project);

project.pluginManager.apply(CheckstylePrecommitPlugin)
project.pluginManager.apply(ForbiddenApisPrecommitPlugin)
project.pluginManager.apply(JarHellPrecommitPlugin)
project.pluginManager.apply(ForbiddenPatternsPrecommitPlugin)
project.pluginManager.apply(LicenseHeadersPrecommitPlugin)
project.pluginManager.apply(FilePermissionsPrecommitPlugin)
project.pluginManager.apply(ThirdPartyAuditPrecommitPlugin)
project.pluginManager.apply(TestingConventionsPrecommitPlugin)
project.getPluginManager().apply(ThirdPartyAuditPrecommitPlugin.class);
project.getPluginManager().apply(CheckstylePrecommitPlugin.class);
project.getPluginManager().apply(ForbiddenApisPrecommitPlugin.class);
project.getPluginManager().apply(ForbiddenPatternsPrecommitPlugin.class);
project.getPluginManager().apply(LicenseHeadersPrecommitPlugin.class);
project.getPluginManager().apply(FilePermissionsPrecommitPlugin.class);
project.getPluginManager().apply(TestingConventionsPrecommitPlugin.class);

// tasks with just tests don't need dependency licenses, so this flag makes adding
// the task optional
if (includeDependencyLicenses) {
project.pluginManager.apply(DependencyLicensesPrecommitPlugin)
project.getPluginManager().apply(DependencyLicensesPrecommitPlugin.class);
}
if (project.path != ':build-tools') {

if (project.getPath().equals(":build-tools") == false) {
/*
* Sadly, build-tools can't have logger-usage-check because that
* would create a circular project dependency between build-tools
Expand All @@ -55,7 +63,8 @@ class PrecommitTasks {
* use the NamingConventionsCheck we break the circular dependency
* here.
*/
project.pluginManager.apply(LoggerUsagePrecommitPlugin)
project.getPluginManager().apply(LoggerUsagePrecommitPlugin.class);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* under the License.
*/

package org.elasticsearch.gradle.precommit
package org.elasticsearch.gradle.internal.precommit

import org.elasticsearch.gradle.internal.InternalPlugin
import org.elasticsearch.gradle.precommit.PrecommitPlugin
import org.elasticsearch.gradle.util.GradleUtils
import org.gradle.api.Project
import org.gradle.api.Task
Expand All @@ -28,7 +30,7 @@ import org.gradle.api.tasks.TaskProvider

import javax.inject.Inject

class LicenseHeadersPrecommitPlugin extends PrecommitPlugin {
class LicenseHeadersPrecommitPlugin extends PrecommitPlugin implements InternalPlugin {

private ProviderFactory providerFactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 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
* 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
Expand All @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.gradle.precommit
package org.elasticsearch.gradle.internal.precommit

import org.apache.rat.anttasks.Report
import org.apache.rat.anttasks.SubstringLicenseMatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class PluginBuildPlugin implements Plugin<Project> {
PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project)
configureDependencies(project)

boolean isXPackModule = project.path.startsWith(':x-pack:plugin') || project.path.startsWith(':x-pack:quota-aware-fs')
boolean isModule = project.path.startsWith(':modules:') || isXPackModule

createBundleTasks(project, extension)

project.afterEvaluate {
Expand Down Expand Up @@ -104,40 +101,47 @@ class PluginBuildPlugin implements Plugin<Project> {
expand(properties)
inputs.properties(properties)
}
if (isModule == false || isXPackModule) {
addNoticeGeneration(project, extension1)
BuildParams.withInternalBuild {
boolean isXPackModule = project.path.startsWith(':x-pack:plugin') || project.path.startsWith(':x-pack:quota-aware-fs')
boolean isModule = project.path.startsWith(':modules:') || isXPackModule
if (isModule == false || isXPackModule) {
addNoticeGeneration(project, extension1)
}
}
}

// We've ported this from multiple build scripts where we see this pattern into
// an extension method as a first step of consolidation.
// We might want to port this into a general pattern later on.
project.ext.addQaCheckDependencies = {
project.afterEvaluate {
// let check depend on check tasks of qa sub-projects
def checkTaskProvider = project.tasks.named("check")
def qaSubproject = project.subprojects.find { it.path == project.path + ":qa" }
if(qaSubproject) {
qaSubproject.subprojects.each {p ->
checkTaskProvider.configure {it.dependsOn(p.path + ":check") }
BuildParams.withInternalBuild {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would comment above but GitHub sucks. We should similarly wrap all the isModule stuff above in this check. For external projects it will always be a plugin, not a module, so we shouldn't accidentally treat it as such if an external author incidentally uses conflicting project naming conventions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// We've ported this from multiple build scripts where we see this pattern into
// an extension method as a first step of consolidation.
// We might want to port this into a general pattern later on.
project.ext.addQaCheckDependencies = {
Copy link
Contributor Author

@breskeby breskeby Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need this for internal builds

project.afterEvaluate {
// let check depend on check tasks of qa sub-projects
def checkTaskProvider = project.tasks.named("check")
def qaSubproject = project.subprojects.find { it.path == project.path + ":qa" }
if(qaSubproject) {
qaSubproject.subprojects.each {p ->
checkTaskProvider.configure {it.dependsOn(p.path + ":check") }
}
}
}
}
}

project.tasks.named('testingConventions').configure {
naming.clear()
naming {
Tests {
baseClass 'org.apache.lucene.util.LuceneTestCase'
}
IT {
baseClass 'org.elasticsearch.test.ESIntegTestCase'
baseClass 'org.elasticsearch.test.rest.ESRestTestCase'
baseClass 'org.elasticsearch.test.ESSingleNodeTestCase'
project.tasks.named('testingConventions').configure {
naming.clear()
naming {
Tests {
baseClass 'org.apache.lucene.util.LuceneTestCase'
}
IT {
baseClass 'org.elasticsearch.test.ESIntegTestCase'
baseClass 'org.elasticsearch.test.rest.ESRestTestCase'
baseClass 'org.elasticsearch.test.ESSingleNodeTestCase'
}
}
}
}

project.configurations.getByName('default')
.extendsFrom(project.configurations.getByName('runtimeClasspath'))
// allow running ES with this plugin in the foreground of a build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.elasticsearch.gradle.RepositoriesSetupPlugin
import org.elasticsearch.gradle.info.BuildParams
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
import org.elasticsearch.gradle.internal.precommit.InternalPrecommitTasks
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.gradle.api.InvalidUserDataException
Expand Down Expand Up @@ -54,8 +55,8 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
void apply(Project project) {
if (project.pluginManager.hasPlugin('elasticsearch.build')) {
throw new InvalidUserDataException('elasticsearch.standalone-test '
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
project.rootProject.pluginManager.apply(GlobalBuildInfoPlugin)
project.pluginManager.apply(JavaBasePlugin)
Expand Down Expand Up @@ -92,6 +93,10 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
idea.module.testSourceDirs += testSourceSet.java.srcDirs
idea.module.scopes.put('TEST', [plus: [project.configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)]] as Map<String, Collection<Configuration>>)

PrecommitTasks.create(project, false)
BuildParams.withInternalBuild {
InternalPrecommitTasks.create(project, false)
}.orElse {
PrecommitTasks.create(project)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
package org.elasticsearch.gradle.test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we go ahead and port this to Java too?

Copy link
Contributor Author

@breskeby breskeby Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we can't at the moment. Whats blocking porting most groovy classes here to java is the AntTask class and classes inheriting this one. It makes use of groovys ant builder. I'm sure we can rewrite the LicenseHeadersTask task in a way to not rely on ant under the hood and then move most of the precommit stuff over to plain java. But not as part of this PR


import groovy.transform.CompileStatic
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.ElasticsearchJavaPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.gradle.test;

import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask;
import org.elasticsearch.gradle.precommit.ForbiddenPatternsTask;
import org.elasticsearch.gradle.internal.precommit.ForbiddenPatternsTask;
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
import org.elasticsearch.gradle.testclusters.TestClustersAware;
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ private static String propertyName(String methodName) {
return propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);
}

public static InternalMarker withInternalBuild(Runnable configBlock) {
if (isInternal()) {
configBlock.run();
return InternalMarker.INTERNAL;
} else {
return InternalMarker.EXTERNAL;
}
}

public enum InternalMarker {
INTERNAL(true),
EXTERNAL(false);

private final boolean internal;

InternalMarker(boolean internal) {
this.internal = internal;
}

public void orElse(Runnable configBlock) {
if (internal == false) {
configBlock.run();
}
}

public boolean isInternal() {
return internal;
}
}

public static class MutableBuildParams {
private static MutableBuildParams INSTANCE = new MutableBuildParams();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.gradle.VersionProperties;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.ArchiveOperations;
Expand All @@ -42,7 +41,7 @@

import static org.elasticsearch.gradle.util.Util.capitalize;

public class InternalDistributionArchiveCheckPlugin implements Plugin<Project> {
public class InternalDistributionArchiveCheckPlugin implements InternalPlugin {

private ArchiveOperations archiveOperations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.gradle.EmptyDirTask;
import org.elasticsearch.gradle.tar.SymbolicLinkPreservingTar;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.plugins.BasePlugin;
Expand Down Expand Up @@ -52,7 +51,7 @@
* - the unpacked variant is used by consumers like test cluster definitions
* 4. Having per-distribution sub-projects means we can build them in parallel.
*/
public class InternalDistributionArchiveSetupPlugin implements Plugin<Project> {
public class InternalDistributionArchiveSetupPlugin implements InternalPlugin {

public static final String DEFAULT_CONFIGURATION_NAME = "default";
public static final String EXTRACTED_CONFIGURATION_NAME = "extracted";
Expand Down
Loading