This commit is contained in:
RafayAhmad7548 2024-09-09 16:59:28 +05:00
parent 2992f4f408
commit 4f46de8d00
3330 changed files with 394553 additions and 76939 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
#safe table
#Sun Sep 08 10:44:29 PKT 2024
.orphans=12
.mainData=12
.contributors=12
.namespaces=12
.extraData=12
.contributions=12
.table=12
.crc5ceaff65.v1

View file

@ -0,0 +1,10 @@
#safe table
#Mon Sep 09 15:55:39 PKT 2024
.orphans=13
.mainData=13
.contributors=13
.namespaces=13
.extraData=13
.contributions=13
.table=13
.crc7b7e9904.v1

View file

@ -0,0 +1,4 @@
#safe table
#Sun Sep 08 10:45:03 PKT 2024
framework.info=25
.crc43586c94.v1

View file

@ -0,0 +1,4 @@
#safe table
#Mon Sep 09 15:54:08 PKT 2024
framework.info=26
.crc380d39e0.v1

View file

@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright (c) 2022 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.PluginContainer
import org.gradle.api.tasks.compile.CompileOptions
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.tooling.provider.model.ToolingModelBuilder
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.gradle.util.GradleVersion
import javax.inject.Inject
class GradleAnnotationProcessorPatchPlugin implements Plugin<Project> {
private final ToolingModelBuilderRegistry registry
@Inject
GradleAnnotationProcessorPatchPlugin(ToolingModelBuilderRegistry registry) {
this.registry = registry
}
@Override
void apply(Project project) {
this.registry.register(new AnnotationProcessorModelBuilder())
}
private static class AnnotationProcessorModelBuilder implements ToolingModelBuilder {
@Override
boolean canBuild(String modelName) {
return "java.util.Map" == modelName
}
@Override
Object buildAll(String modelName, Project rootProject) {
final GradleVersion current = GradleVersion.current().getBaseVersion()
if (current < GradleVersion.version("5.2")) {
return Collections.emptyMap()
}
Set<Project> allProject = rootProject.getAllprojects()
Map<File, Map<String, Object>> annotationProcessorInfo = new HashMap<>()
for (Project project : allProject) {
PluginContainer plugins = project.getPlugins()
if (!hasPlugin(plugins, "java")) {
continue
}
Set<File> processors = new HashSet<>()
List<String> compilerArgs = new LinkedList<>()
// Compiler args for test are ignored.
// Due to JDT does not differentiate the args between main and test.
collectApConfiguration(project, "compileJava", processors, compilerArgs)
Map<String, Object> apInfo = new HashMap<>()
if (processors.size() > 0) {
apInfo.put("processors", processors)
apInfo.put("compilerArgs", compilerArgs)
}
annotationProcessorInfo.put(project.getProjectDir(), apInfo)
}
return annotationProcessorInfo
}
private static boolean hasPlugin(PluginContainer plugins, String pluginId) {
return plugins.findPlugin(pluginId) != null
}
private void collectApConfiguration(project, compileTaskName, processors, compilerArgs) {
JavaCompile javaCompile = project.getTasks().findByName(compileTaskName)
if (javaCompile != null) {
CompileOptions options = javaCompile.getOptions()
if (!options.compilerArgs.contains("-proc:none")) {
FileCollection apPath = options.getAnnotationProcessorPath()
if (apPath != null) {
processors.addAll(apPath.getFiles())
}
compilerArgs.addAll(options.getCompilerArgs())
}
}
}
}
}
allprojects {
afterEvaluate {
it.getPlugins().apply(GradleAnnotationProcessorPatchPlugin)
}
}

View file

@ -0,0 +1,10 @@
allprojects {
project.plugins.withId("eclipse", {
// Add prefix when project name has conflicts with root project name
if (project != rootProject && rootProject.name.toLowerCase() == project.name.toLowerCase()) {
eclipse.project.name = (rootProject.name + project.path).replaceAll(':', '-')
} else if (project == rootProject && rootProject.name.toLowerCase() != project.projectDir.name.toLowerCase()) {
eclipse.project.name = (rootProject.name + '-' + project.projectDir.name).replaceAll(':', '-')
}
})
}

View file

@ -0,0 +1,187 @@
import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.ClasspathEntry
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import java.lang.reflect.InvocationTargetException
class ProtobufPatchPlugin implements Plugin<Project> {
/**
* The protobuf task names that will compile proto file to java source code.
*/
private static final List<String> TASK_NAMES = Arrays.asList("generateProto", "generateTestProto")
/**
* The Gradle Eclipse plugin id.
*/
private static final String ECLIPSE_PLUGIN = "eclipse"
/**
* The Gradle Protobuf plugin id.
*/
private static final String PROTOBUF_PLUGIN = "com.google.protobuf"
/**
* Constant for the name of the ignore optional compile problems attribute.
*/
private static final String IGNORE_OPTIONAL_PROBLEMS = "ignore_optional_problems"
/**
* Constant for the name of the module attribute.
*/
private static final String OPTIONAL = "optional"
/**
* Constant for the name of the test attribute.
*/
private static final String TEST = "test"
private static final String PROTOBUF_GENERATED_SOURCE = "protobuf_generated_source"
@Override
void apply(Project project) {
project.afterEvaluate {
project.plugins.withId(ECLIPSE_PLUGIN) {
project.plugins.withId(PROTOBUF_PLUGIN) {
EclipseModel model = project.getExtensions().findByType(EclipseModel)
model.classpath.file.whenMerged { Classpath cp ->
File projectDir = project.getProjectDir()
for (final String taskName : TASK_NAMES) {
Task task = getTaskByName(project, taskName)
if (task == null) {
continue
}
Object sourceSetObj = getSourceSet(task);
if (!(sourceSetObj instanceof SourceSet)) {
continue
}
String sourceSetName = ((SourceSet) sourceSetObj).name
Object outputSourceDirectorySet = getOutputSourceDirectorySet(task)
if (!(outputSourceDirectorySet instanceof SourceDirectorySet)) {
continue;
}
SourceDirectorySet sourceDirectorySet = (SourceDirectorySet) outputSourceDirectorySet
Set<File> srcDirs = sourceDirectorySet.getSrcDirs()
for (File srcDir : srcDirs) {
// buildship requires the folder exists on disk, otherwise
// it will be ignored when updating classpath file, see:
// https://github.com/eclipse/buildship/issues/1196
srcDir.mkdirs();
String relativePath = projectDir.toPath().relativize(srcDir.toPath()).toString()
// remove trailing slash
if (relativePath.endsWith("/")) {
relativePath = relativePath.substring(0, relativePath.length() - 1)
}
SourceFolder entry = new SourceFolder(relativePath, getOutputPath(cp, sourceSetName))
entry.entryAttributes.put(PROTOBUF_GENERATED_SOURCE, "true")
entry.entryAttributes.put(OPTIONAL, "true")
entry.entryAttributes.put(IGNORE_OPTIONAL_PROBLEMS, "true")
// check if output is not null here because test source folder
// must have a separate output folder in Eclipse
if (entry.output != null && isTest(task)) {
entry.entryAttributes.put(TEST, "true")
}
cp.entries.add(entry)
}
}
}
}
}
}
}
Task getTaskByName(Project project, String name) {
try {
return project.getTasks().getByName(name)
} catch (UnknownTaskException e) {
return null;
}
}
/**
* Get the output source directory set of the proto generation task. The source directories
* will be added to the Eclipse classpath entries.
*/
Object getOutputSourceDirectorySet(Task task) {
try {
return task.getClass().getMethod("getOutputSourceDirectorySet").invoke(task)
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
return null
}
}
/**
* Get the source set of the proto generation task. The source set name will be used
* to determine the output path.
*/
Object getSourceSet(Task task) {
try {
return task.getClass().getMethod("getSourceSet").invoke(task)
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
return null
}
}
/**
* Get if it's generate test proto task or not.
*/
boolean isTest(Task task) {
try {
return (boolean) task.getClass().getMethod("getIsTest").invoke(task)
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
return false
}
}
/**
* Get the output path according to the source set name, if no valid path can be
* found, <code>null</code> will return.
*/
String getOutputPath(Classpath classpath, String sourceSetName) {
String path = "bin/" + sourceSetName
if (isValidOutput(classpath, path)) {
return path
}
// fallback to default output
return null
}
/**
* Check if the output path is valid or not.
* See: org.eclipse.jdt.internal.core.ClasspathEntry#validateClasspath()
*/
boolean isValidOutput(Classpath classpath, String path) {
Set<String> outputs = new HashSet<>()
for (ClasspathEntry cpe : classpath.getEntries()) {
if (cpe instanceof SourceFolder) {
outputs.add(((SourceFolder) cpe).getOutput())
}
}
for (String output : outputs) {
if (output == null || output.isEmpty()) {
continue
}
if (Objects.equals(output, path)) {
continue
}
// Eclipse does not allow nested output path
if (output.startsWith(path) || path.startsWith(output)) {
return false
}
}
return true
}
}
allprojects {
afterEvaluate {
it.getPlugins().apply(ProtobufPatchPlugin)
}
}

Some files were not shown because too many files have changed in this diff Show more