-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 6.x: Introduce mapping version to index metadata (#33147) Move non duplicated actions back into xpack core (#32952) HLRC: Create server agnostic request and response (#32912) Build: forked compiler max memory matches jvmArgs (#33138) * Added breaking change section for GROUP BY behavior: now it considers null or empty values as a separate group/bucket. Previously, they were ignored. * This is part of backporting of #32832 SQL: Enable aggregations to create a separate bucket for missing values (#32832) [TEST] version guard for reload rest-api-spec Fix grammar in contributing docs APM server monitoring (#32515) Support only string `format` in date, root object & date range (#28117) [Rollup] Move toBuilders() methods out of rollup config objects (#32585) Accept Gradle build scan agreement (#30645) Fix forbiddenapis on java 11 (#33116) Run forbidden api checks with runtimeJavaVersion (#32947) Apply publishing to genreate pom (#33094) Fix a mappings update test (#33146) Reload Secure Settings REST specs & docs (#32990) Refactor CachingUsernamePassword realm (#32646)
- Loading branch information
Showing
133 changed files
with
5,710 additions
and
559 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
166 changes: 166 additions & 0 deletions
166
buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ForbiddenApisCliTask.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,166 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.gradle.precommit; | ||
|
||
import de.thetaphi.forbiddenapis.cli.CliMain; | ||
import org.gradle.api.Action; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.JavaVersion; | ||
import org.gradle.api.file.FileCollection; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFiles; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.SkipWhenEmpty; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.process.JavaExecSpec; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ForbiddenApisCliTask extends DefaultTask { | ||
|
||
private final Logger logger = Logging.getLogger(ForbiddenApisCliTask.class); | ||
private FileCollection signaturesFiles; | ||
private List<String> signatures = new ArrayList<>(); | ||
private Set<String> bundledSignatures = new LinkedHashSet<>(); | ||
private Set<String> suppressAnnotations = new LinkedHashSet<>(); | ||
private JavaVersion targetCompatibility; | ||
private FileCollection classesDirs; | ||
private Action<JavaExecSpec> execAction; | ||
|
||
@Input | ||
public JavaVersion getTargetCompatibility() { | ||
return targetCompatibility; | ||
} | ||
|
||
public void setTargetCompatibility(JavaVersion targetCompatibility) { | ||
if (targetCompatibility.compareTo(JavaVersion.VERSION_1_10) > 0) { | ||
logger.warn( | ||
"Target compatibility is set to {} but forbiddenapis only supports up to 10. Will cap at 10.", | ||
targetCompatibility | ||
); | ||
this.targetCompatibility = JavaVersion.VERSION_1_10; | ||
} else { | ||
this.targetCompatibility = targetCompatibility; | ||
} | ||
} | ||
|
||
public Action<JavaExecSpec> getExecAction() { | ||
return execAction; | ||
} | ||
|
||
public void setExecAction(Action<JavaExecSpec> execAction) { | ||
this.execAction = execAction; | ||
} | ||
|
||
@OutputFile | ||
public File getMarkerFile() { | ||
return new File( | ||
new File(getProject().getBuildDir(), "precommit"), | ||
getName() | ||
); | ||
} | ||
|
||
@InputFiles | ||
@SkipWhenEmpty | ||
public FileCollection getClassesDirs() { | ||
return classesDirs.filter(File::exists); | ||
} | ||
|
||
public void setClassesDirs(FileCollection classesDirs) { | ||
this.classesDirs = classesDirs; | ||
} | ||
|
||
@InputFiles | ||
public FileCollection getSignaturesFiles() { | ||
return signaturesFiles; | ||
} | ||
|
||
public void setSignaturesFiles(FileCollection signaturesFiles) { | ||
this.signaturesFiles = signaturesFiles; | ||
} | ||
|
||
@Input | ||
public List<String> getSignatures() { | ||
return signatures; | ||
} | ||
|
||
public void setSignatures(List<String> signatures) { | ||
this.signatures = signatures; | ||
} | ||
|
||
@Input | ||
public Set<String> getBundledSignatures() { | ||
return bundledSignatures; | ||
} | ||
|
||
public void setBundledSignatures(Set<String> bundledSignatures) { | ||
this.bundledSignatures = bundledSignatures; | ||
} | ||
|
||
@Input | ||
public Set<String> getSuppressAnnotations() { | ||
return suppressAnnotations; | ||
} | ||
|
||
public void setSuppressAnnotations(Set<String> suppressAnnotations) { | ||
this.suppressAnnotations = suppressAnnotations; | ||
} | ||
|
||
@TaskAction | ||
public void runForbiddenApisAndWriteMarker() throws IOException { | ||
getProject().javaexec((JavaExecSpec spec) -> { | ||
execAction.execute(spec); | ||
spec.setMain(CliMain.class.getName()); | ||
// build the command line | ||
getSignaturesFiles().forEach(file -> spec.args("-f", file.getAbsolutePath())); | ||
getSuppressAnnotations().forEach(annotation -> spec.args("--suppressannotation", annotation)); | ||
getBundledSignatures().forEach(bundled -> { | ||
// there's no option for target compatibility so we have to interpret it | ||
final String prefix; | ||
if (bundled.equals("jdk-system-out") || | ||
bundled.equals("jdk-reflection") || | ||
bundled.equals("jdk-non-portable")) { | ||
prefix = ""; | ||
} else { | ||
prefix = "-" + ( | ||
getTargetCompatibility().compareTo(JavaVersion.VERSION_1_9) >= 0 ? | ||
getTargetCompatibility().getMajorVersion() : | ||
"1." + getTargetCompatibility().getMajorVersion()) | ||
; | ||
} | ||
spec.args("-b", bundled + prefix); | ||
} | ||
); | ||
getClassesDirs().forEach(dir -> | ||
spec.args("-d", dir) | ||
); | ||
}); | ||
Files.write(getMarkerFile().toPath(), Collections.emptyList()); | ||
} | ||
|
||
} |
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
Oops, something went wrong.