Skip to content

Commit d57adbd

Browse files
committed
WIP
1 parent 9be742e commit d57adbd

File tree

3 files changed

+327
-71
lines changed

3 files changed

+327
-71
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.dependencies.rules;
11+
12+
import org.gradle.api.artifacts.ComponentMetadataContext;
13+
import org.gradle.api.artifacts.ComponentMetadataRule;
14+
15+
import java.util.List;
16+
17+
public class DependencyRemovalByNameRule implements ComponentMetadataRule {
18+
19+
private final List<String> modulesToRemove;
20+
21+
public DependencyRemovalByNameRule(String... modulesToRemove) {
22+
this.modulesToRemove = List.of(modulesToRemove);
23+
}
24+
25+
@Override
26+
public void execute(ComponentMetadataContext context) {
27+
context.getDetails().allVariants(variants -> {
28+
variants.withDependencies(dependencies -> {
29+
dependencies.removeIf(metadata -> modulesToRemove.contains(metadata.getName()));
30+
});
31+
});
32+
}
33+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/dependencies/rules/ExcludeTransitivesRule.java

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,34 @@ public abstract class ExcludeTransitivesRule implements ComponentMetadataRule {
2222

2323
@Override
2424
public void execute(ComponentMetadataContext context) {
25-
26-
if (context.getDetails().getId().getGroup().startsWith("org.elasticsearch") == false) {
27-
28-
29-
context.getDetails().allVariants(variant -> {
30-
// .attribute(
31-
// DependencyContext.CONTEXT_ATTRIBUTE,
32-
// getObjects().named(DependencyContext.class, DependencyContext.CODE_QUALITY)
33-
// );
34-
DependencyContext customValue = variant.getAttributes().getAttribute(DependencyContext.CONTEXT_ATTRIBUTE);
35-
if(customValue != null) {
36-
return;
25+
context.getDetails().allVariants(variant -> {
26+
variant.withDependencies(dependencies -> {
27+
// Exclude all transitive dependencies
28+
if(dependencies.isEmpty()) {
29+
System.out.println(context.getDetails().getId().getGroup() + ":" + context.getDetails().getId().getName());
3730
}
38-
// if ("some-value".equals(customValue)) {
39-
// System.out.println("customValue = " + customValue);
40-
// return;
41-
// }
42-
43-
variant.withDependencies(dependencies -> {
44-
// dependencies.clear();
45-
dependencies.removeIf(directDependencyMetadata -> { return true; });
46-
});
31+
dependencies.clear();
32+
// dependencies.removeIf(p -> {
33+
// System.out.println("p.getName() = " + p.getName());
34+
// return true;
35+
// });
4736
});
48-
49-
}
50-
}
51-
52-
private boolean isCodeQuality(VariantMetadata variant) {
53-
// System.out.println("CodeQualityRule#context#variantName = " + ((VariantMetadataAdapter)variant).variantName);
54-
System.out.println("ExcludeTransitivesRule#context#isCodeQuality = " + ((VariantMetadataAdapter) variant).toString());
55-
try {
56-
java.lang.reflect.Field field = VariantMetadataAdapter.class.getDeclaredField("variantName");
57-
field.setAccessible(true);
58-
Object variantName = field.get(variant);
59-
System.out.println("ExcludeTransitivesRule#context#variantName = " + variantName);
60-
} catch (Exception e) {
61-
System.out.println("Failed to access variantName: " + e.getMessage());
62-
}
63-
DependencyContext attribute = variant.getAttributes().getAttribute(DependencyContext.CONTEXT_ATTRIBUTE);
64-
return attribute != null && DependencyContext.CODE_QUALITY.equals(attribute.getName());
37+
});
6538
}
39+
//
40+
// private boolean isCodeQuality(VariantMetadata variant) {
41+
// // System.out.println("CodeQualityRule#context#variantName = " + ((VariantMetadataAdapter)variant).variantName);
42+
// System.out.println("ExcludeTransitivesRule#context#isCodeQuality = " + ((VariantMetadataAdapter) variant).toString());
43+
// try {
44+
// java.lang.reflect.Field field = VariantMetadataAdapter.class.getDeclaredField("variantName");
45+
// field.setAccessible(true);
46+
// Object variantName = field.get(variant);
47+
// System.out.println("ExcludeTransitivesRule#context#variantName = " + variantName);
48+
// } catch (Exception e) {
49+
// System.out.println("Failed to access variantName: " + e.getMessage());
50+
// }
51+
// DependencyContext attribute = variant.getAttributes().getAttribute(DependencyContext.CONTEXT_ATTRIBUTE);
52+
// return attribute != null && DependencyContext.CODE_QUALITY.equals(attribute.getName());
53+
// }
6654

6755
}

0 commit comments

Comments
 (0)