Skip to content

Commit

Permalink
Annotate @OverRide (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Sep 19, 2024
1 parent bf1fb10 commit da6c057
Show file tree
Hide file tree
Showing 33 changed files with 105 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RelocatorRemapper extends Remapper {
return !relocators.empty
}

@Override
Object mapValue(Object object) {
if (object instanceof String) {
String name = (String) object
Expand Down Expand Up @@ -83,6 +84,7 @@ class RelocatorRemapper extends Remapper {
return super.mapValue(object)
}

@Override
String map(String name) {
String value = name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
Set<ResolvedDependency> includedDependencies,
Set<ResolvedDependency> excludedDependencies)

@Override
FileCollection resolve(FileCollection configuration) {
Set<ResolvedDependency> includedDeps = []
Set<ResolvedDependency> excludedDeps = []
Expand All @@ -33,6 +34,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
}.flatten())
}

@Override
FileCollection resolve(Collection<FileCollection> configurations) {
configurations.collect {
resolve(it)
Expand All @@ -45,6 +47,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param spec
* @return
*/
@Override
DependencyFilter exclude(Spec<? super ResolvedDependency> spec) {
excludeSpecs << spec
return this
Expand All @@ -56,6 +59,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param spec
* @return
*/
@Override
DependencyFilter include(Spec<? super ResolvedDependency> spec) {
includeSpecs << spec
return this
Expand All @@ -66,6 +70,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param notation
* @return
*/
@Override
Spec<? super ResolvedDependency> project(Map<String, ?> notation) {
dependency(project.dependencies.project(notation))
}
Expand All @@ -76,6 +81,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param notation
* @return
*/
@Override
Spec<? super ResolvedDependency> project(String notation) {
dependency(project.dependencies.project(path: notation, configuration: 'default'))
}
Expand All @@ -85,6 +91,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param notation
* @return
*/
@Override
Spec<? super ResolvedDependency> dependency(Object notation) {
dependency(project.dependencies.create(notation))
}
Expand All @@ -94,6 +101,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param dependency
* @return
*/
@Override
Spec<? super ResolvedDependency> dependency(Dependency dependency) {
this.dependency({ ResolvedDependency it ->
(!dependency.group || it.moduleGroup.matches(dependency.group)) &&
Expand All @@ -107,6 +115,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter {
* @param spec
* @return
*/
@Override
Spec<? super ResolvedDependency> dependency(Closure spec) {
return Specs.<ResolvedDependency>convertClosureToSpec(spec)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DefaultZipCompressor implements ZipCompressor {
zip64Mode = allowZip64Mode ? Zip64Mode.AsNeeded : Zip64Mode.Never
}

@Override
ZipOutputStream createArchiveOutputStream(File destination) {
try {
ZipOutputStream zipOutputStream = new ZipOutputStream(destination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
*/
package com.github.jengelman.gradle.plugins.shadow.internal

import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.internal.file.archive.compression.ArchiveOutputStreamFactory

interface ZipCompressor extends ArchiveOutputStreamFactory {

ZipOutputStream createArchiveOutputStream(File destination)

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class SimpleRelocator implements Relocator {
return false
}

@Override
boolean canRelocatePath(String path) {
if (rawString) {
return Pattern.compile(pathPattern).matcher(path).find()
Expand Down Expand Up @@ -176,12 +177,14 @@ class SimpleRelocator implements Relocator {
return false
}

@Override
boolean canRelocateClass(String className) {
return !rawString &&
className.indexOf('/') < 0 &&
canRelocatePath(className.replace('.', '/'))
}

@Override
String relocatePath(RelocatePathContext context) {
String path = context.path
context.stats.relocate(pathPattern, shadedPathPattern)
Expand All @@ -192,12 +195,14 @@ class SimpleRelocator implements Relocator {
}
}

@Override
String relocateClass(RelocateClassContext context) {
String clazz = context.className
context.stats.relocate(pathPattern, shadedPathPattern)
return clazz.replaceFirst(pattern, shadedPattern)
}

@Override
String applyToSourceContent(String sourceContent) {
if (rawString) {
return sourceContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class DefaultInheritManifest implements InheritManifest {
this.fileResolver = fileResolver
}

@Override
InheritManifest inheritFrom(Object... inheritPaths) {
inheritFrom(inheritPaths, null)
return this
}

@Override
InheritManifest inheritFrom(Object inheritPaths, Closure closure) {
DefaultManifestMergeSpec mergeSpec = new DefaultManifestMergeSpec()
mergeSpec.from(inheritPaths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class ShadowCopyAction implements CopyAction {
return lastName.endsWith('.class')
}

@Override
RelativeArchivePath getParent() {
if (!segments || segments.length == 1) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public ShadowJar() {
});
}

@Override
public ShadowJar minimize() {
minimizeJar = true;
return this;
}

@Override
public ShadowJar minimize(Action<DependencyFilter> c) {
minimize();
if (c != null) {
Expand Down Expand Up @@ -153,6 +155,7 @@ protected ZipCompressor getInternalCompressor() {
}

@TaskAction
@Override
protected void copy() {
if (enableRelocation) {
RelocationUtil.configureRelocation(this, relocationPrefix);
Expand Down Expand Up @@ -183,6 +186,7 @@ protected PatternSet getRootPatternSet() {
* @param c the configuration of the filter
* @return this
*/
@Override
public ShadowJar dependencies(Action<DependencyFilter> c) {
if (c != null) {
c.execute(dependencyFilter);
Expand All @@ -196,6 +200,7 @@ public ShadowJar dependencies(Action<DependencyFilter> c) {
* @param clazz the transformer to add. Must have a no-arg constructor
* @return this
*/
@Override
public ShadowJar transform(Class<? extends Transformer> clazz) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
return transform(clazz, null);
}
Expand All @@ -207,6 +212,7 @@ public ShadowJar transform(Class<? extends Transformer> clazz) throws Instantiat
* @param c the configuration for the transformer
* @return this
*/
@Override
public <T extends Transformer> ShadowJar transform(Class<T> clazz, Action<T> c) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
T transformer = clazz.getDeclaredConstructor().newInstance();
addTransform(transformer, c);
Expand All @@ -223,6 +229,7 @@ private boolean isCacheableTransform(Class<? extends Transformer> clazz) {
* @param transformer the transformer instance to add
* @return this
*/
@Override
public ShadowJar transform(Transformer transformer) {
addTransform(transformer, null);
return this;
Expand All @@ -241,6 +248,7 @@ private <T extends Transformer> void addTransform(T transformer, Action<T> c) {
*
* @return this
*/
@Override
public ShadowJar mergeServiceFiles() {
try {
transform(ServiceFileTransformer.class);
Expand All @@ -255,6 +263,7 @@ public ShadowJar mergeServiceFiles() {
*
* @return this
*/
@Override
public ShadowJar mergeServiceFiles(final String rootPath) {
try {
transform(ServiceFileTransformer.class, serviceFileTransformer -> serviceFileTransformer.setPath(rootPath));
Expand All @@ -269,6 +278,7 @@ public ShadowJar mergeServiceFiles(final String rootPath) {
*
* @return this
*/
@Override
public ShadowJar mergeServiceFiles(Action<ServiceFileTransformer> configureClosure) {
try {
transform(ServiceFileTransformer.class, configureClosure);
Expand All @@ -283,6 +293,7 @@ public ShadowJar mergeServiceFiles(Action<ServiceFileTransformer> configureClosu
*
* @return this
*/
@Override
public ShadowJar mergeGroovyExtensionModules() {
try {
transform(GroovyExtensionModuleTransformer.class);
Expand All @@ -297,6 +308,7 @@ public ShadowJar mergeGroovyExtensionModules() {
*
* @return this
*/
@Override
public ShadowJar append(final String resourcePath) {
try {
transform(AppendingTransformer.class, transformer -> transformer.setResource(resourcePath));
Expand All @@ -313,6 +325,7 @@ public ShadowJar append(final String resourcePath) {
* @param destination the destination package
* @return this
*/
@Override
public ShadowJar relocate(String pattern, String destination) {
return relocate(pattern, destination, null);
}
Expand All @@ -325,6 +338,7 @@ public ShadowJar relocate(String pattern, String destination) {
* @param configure the configuration of the relocator
* @return this
*/
@Override
public ShadowJar relocate(String pattern, String destination, Action<SimpleRelocator> configure) {
SimpleRelocator relocator = new SimpleRelocator(pattern, destination, new ArrayList<>(), new ArrayList<>());
addRelocator(relocator, configure);
Expand All @@ -337,6 +351,7 @@ public ShadowJar relocate(String pattern, String destination, Action<SimpleReloc
* @param relocator the relocator instance to add
* @return this
*/
@Override
public ShadowJar relocate(Relocator relocator) {
addRelocator(relocator, null);
return this;
Expand All @@ -348,6 +363,7 @@ public ShadowJar relocate(Relocator relocator) {
* @param relocatorClass the relocator class to add. Must have a no-arg constructor.
* @return this
*/
@Override
public ShadowJar relocate(Class<? extends Relocator> relocatorClass) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
return relocate(relocatorClass, null);
}
Expand All @@ -367,6 +383,7 @@ private <R extends Relocator> void addRelocator(R relocator, Action<R> configure
* @param configure the configuration for the relocator
* @return this
*/
@Override
public <R extends Relocator> ShadowJar relocate(Class<R> relocatorClass, Action<R> configure) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
R relocator = relocatorClass.getDeclaredConstructor().newInstance();
addRelocator(relocator, configure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@ class ApacheLicenseResourceTransformer implements Transformer {

private static final String LICENSE_TXT_PATH = "META-INF/LICENSE.txt"

@Override
boolean canTransformResource(FileTreeElement element) {
def path = element.relativePath.pathString
return LICENSE_PATH.equalsIgnoreCase(path) ||
LICENSE_TXT_PATH.regionMatches(true, 0, path, 0, LICENSE_TXT_PATH.length())
}

@Override
void transform(TransformerContext context) {

}

@Override
boolean hasTransformedResource() {
return false
}

@Override
void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ApacheNoticeResourceTransformer implements Transformer {

private static final String NOTICE_TXT_PATH = "META-INF/NOTICE.txt"

@Override
boolean canTransformResource(FileTreeElement element) {
def path = element.relativePath.pathString
if (NOTICE_PATH.equalsIgnoreCase(path) || NOTICE_TXT_PATH.equalsIgnoreCase(path)) {
Expand All @@ -91,6 +92,7 @@ class ApacheNoticeResourceTransformer implements Transformer {
return false
}

@Override
void transform(TransformerContext context) {
if (entries.isEmpty()) {
String year = new SimpleDateFormat("yyyy").format(new Date())
Expand Down Expand Up @@ -170,10 +172,12 @@ class ApacheNoticeResourceTransformer implements Transformer {
}
}

@Override
boolean hasTransformedResource() {
return true
}

@Override
void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) {
ZipEntry zipEntry = new ZipEntry(NOTICE_PATH)
zipEntry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, zipEntry.time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AppendingTransformer implements Transformer {
*/
private ByteArrayOutputStream data

@Override
boolean canTransformResource(FileTreeElement element) {
def path = element.relativePath.pathString
if (resource != null && resource.equalsIgnoreCase(path)) {
Expand All @@ -55,6 +56,7 @@ class AppendingTransformer implements Transformer {
return false
}

@Override
void transform(TransformerContext context) {
if (data == null) {
data = new ByteArrayOutputStream()
Expand All @@ -66,10 +68,12 @@ class AppendingTransformer implements Transformer {
context.is.close()
}

@Override
boolean hasTransformedResource() {
return data?.size() > 0
}

@Override
void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) {
if (data == null) {
data = new ByteArrayOutputStream()
Expand Down
Loading

0 comments on commit da6c057

Please sign in to comment.