forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The azure sdk internally dynamically constructs its client classes. However, one of these, for the blob storage is private. This has been fixed upstream, but until that is released, the client is unuseable without the newProxyInPackage permission. Rather than grant that permission, this commit makes the class in question public by patching the azure class file when building the azure repository plugin. relates Azure/azure-sdk-for-java#17368
- Loading branch information
Showing
6 changed files
with
125 additions
and
10 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
90 changes: 90 additions & 0 deletions
90
buildSrc/src/main/java/org/elasticsearch/gradle/JavaClassPublicifier.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,90 @@ | ||
/* | ||
* 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; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.DirectoryProperty; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputDirectory; | ||
import org.gradle.api.tasks.OutputDirectory; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
|
||
import static org.objectweb.asm.Opcodes.ACC_PUBLIC; | ||
|
||
/** | ||
* A task to manipulate an existing class file. | ||
*/ | ||
public class JavaClassPublicifier extends DefaultTask { | ||
|
||
private String classFile; | ||
private DirectoryProperty inputDir; | ||
private DirectoryProperty outputDir; | ||
|
||
public JavaClassPublicifier() { | ||
this.inputDir = getProject().getObjects().directoryProperty(); | ||
this.outputDir = getProject().getObjects().directoryProperty(); | ||
} | ||
|
||
@Input | ||
public String getClassFile() { | ||
return classFile; | ||
} | ||
|
||
public void setClassFile(String classFile) { | ||
this.classFile = classFile; | ||
} | ||
|
||
@InputDirectory | ||
public DirectoryProperty getInputDir() { | ||
return inputDir; | ||
} | ||
|
||
@OutputDirectory | ||
public DirectoryProperty getOutputDir() { | ||
return outputDir; | ||
} | ||
|
||
@TaskAction | ||
public void adapt() throws IOException { | ||
final ClassNode classNode; | ||
try (InputStream is = Files.newInputStream(inputDir.get().file(classFile).getAsFile().toPath())) { | ||
ClassReader classReader = new ClassReader(is); | ||
classNode = new ClassNode(); | ||
classReader.accept(classNode, ClassReader.EXPAND_FRAMES); | ||
} | ||
|
||
classNode.access |= ACC_PUBLIC; | ||
|
||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); | ||
classNode.accept(classWriter); | ||
|
||
File outputFile = outputDir.get().file(classFile).getAsFile(); | ||
outputFile.getParentFile().mkdirs(); | ||
Files.write(outputFile.toPath(), classWriter.toByteArray()); | ||
} | ||
} |
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,32 @@ | ||
import org.elasticsearch.gradle.JavaClassPublicifier; | ||
|
||
apply plugin: 'elasticsearch.java' | ||
apply plugin: 'com.github.johnrengelman.shadow' | ||
|
||
configurations { | ||
originalJar { | ||
transitive = false | ||
} | ||
} | ||
|
||
dependencies { | ||
originalJar "com.azure:azure-storage-blob:${project.parent.versions.azure}" | ||
implementation "com.azure:azure-storage-blob:${project.parent.versions.azure}" | ||
} | ||
|
||
String blobsServiceClass = 'com/azure/storage/blob/implementation/BlobsImpl$BlobsService.class' | ||
|
||
tasks.create('extractBlobsServiceClass', Copy).configure { | ||
from({ zipTree(configurations.originalJar.singleFile) }) { | ||
include blobsServiceClass | ||
} | ||
into project.file('build/original') | ||
} | ||
|
||
tasks.create('makeBlobsServicePublic', JavaClassPublicifier).configure { | ||
classFile = blobsServiceClass | ||
inputDir = project.layout.buildDirectory.dir('original') | ||
outputDir = project.layout.buildDirectory.dir('modified') | ||
} | ||
|
||
sourceSets.main.java.compiledBy(tasks.named('makeBlobsServicePublic')) { myTask -> myTask.outputDir } |
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
1 change: 0 additions & 1 deletion
1
plugins/repository-azure/licenses/azure-storage-blob-12.9.0.jar.sha1
This file was deleted.
Oops, something went wrong.
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