Skip to content

Commit 2b9bc08

Browse files
committed
Revert "Retrieving all licenses currently used in recipe jars"
This reverts commit 1696e91.
1 parent e629be2 commit 2b9bc08

6 files changed

Lines changed: 1 addition & 137 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/config/ClasspathScanningLoader.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import io.github.classgraph.ClassGraph;
1919
import io.github.classgraph.ClassInfo;
20-
import io.github.classgraph.Resource;
2120
import io.github.classgraph.ScanResult;
2221
import io.micrometer.core.instrument.Metrics;
2322
import io.micrometer.core.instrument.Timer;
@@ -30,9 +29,6 @@
3029
import org.openrewrite.internal.RecipeLoader;
3130
import org.openrewrite.style.NamedStyles;
3231

33-
import java.io.BufferedReader;
34-
import java.io.IOException;
35-
import java.io.InputStreamReader;
3632
import java.lang.reflect.Constructor;
3733
import java.lang.reflect.Modifier;
3834
import java.nio.file.Path;
@@ -45,7 +41,6 @@ public class ClasspathScanningLoader implements ResourceLoader {
4541

4642
private final LinkedHashMap<String, Recipe> recipes = new LinkedHashMap<>();
4743
private final List<NamedStyles> styles = new ArrayList<>();
48-
private final Set<License> licenses = new LinkedHashSet<>();
4944

5045
private final LinkedHashSet<RecipeDescriptor> recipeDescriptors = new LinkedHashSet<>();
5146
private final List<CategoryDescriptor> categoryDescriptors = new ArrayList<>();
@@ -70,7 +65,6 @@ public ClasspathScanningLoader(Properties properties, String[] acceptPackages) {
7065
properties,
7166
emptyList(),
7267
null);
73-
scanLicenses(new ClassGraph().acceptPathsNonRecursive("META-INF"));
7468
};
7569
}
7670

@@ -94,7 +88,6 @@ public ClasspathScanningLoader(Properties properties, ClassLoader classLoader) {
9488
properties,
9589
emptyList(),
9690
classLoader);
97-
scanLicenses(new ClassGraph().acceptPathsNonRecursive("META-INF").overrideClassLoaders(classLoader));
9891
};
9992
}
10093

@@ -113,15 +106,13 @@ public ClasspathScanningLoader(Path jar, Properties properties, Collection<? ext
113106
.ignoreParentClassLoaders()
114107
.overrideClassLoaders(classLoader)
115108
.acceptPaths("META-INF/rewrite"), properties, dependencyResourceLoaders, classLoader);
116-
scanLicenses(new ClassGraph().acceptPathsNonRecursive("META-INF").overrideClassLoaders(classLoader));
117109
};
118110
}
119111

120112
public static ClasspathScanningLoader onlyYaml(Properties properties) {
121113
ClasspathScanningLoader classpathScanningLoader = new ClasspathScanningLoader();
122114
classpathScanningLoader.scanYaml(new ClassGraph().acceptPaths("META-INF/rewrite"),
123115
properties, emptyList(), null);
124-
classpathScanningLoader.scanLicenses(new ClassGraph().acceptPathsNonRecursive("META-INF"));
125116
return classpathScanningLoader;
126117
}
127118

@@ -183,38 +174,6 @@ private void scanClasses(ClassGraph classGraph, ClassLoader classLoader) {
183174
}
184175
}
185176

186-
private void scanLicenses(ClassGraph classGraph) {
187-
try (ScanResult result = classGraph.scan()) {
188-
for (Resource resource : result.getResourcesWithLeafName("MANIFEST.MF")) {
189-
try (Resource resToClose = resource; BufferedReader reader = new BufferedReader(new InputStreamReader(resource.open()))) {
190-
StringBuilder licenseName = new StringBuilder();
191-
StringBuilder licenseUrl = new StringBuilder();
192-
String previousLine = "";
193-
String line;
194-
while ((line = reader.readLine()) != null) {
195-
if (line.toLowerCase().startsWith("license-name:")) {
196-
licenseName = new StringBuilder(line.substring("license-name:".length()).trim());
197-
} else if (line.toLowerCase().startsWith("license-url:")) {
198-
licenseUrl = new StringBuilder(line.substring("license-url:".length()).trim());
199-
}
200-
if (line.startsWith(" ")) {
201-
if (previousLine.toLowerCase().startsWith("license-name:")) {
202-
licenseName.append(line.trim());
203-
} else if (previousLine.toLowerCase().startsWith("license-url:")) {
204-
licenseUrl.append(line.trim());
205-
}
206-
} else {
207-
previousLine = line;
208-
}
209-
}
210-
if (licenseName.length() > 0 && licenseUrl.length() > 0) {
211-
licenses.add(new License(licenseName.toString(), licenseUrl.toString()));
212-
}
213-
} catch (IOException ignored) {}
214-
}
215-
}
216-
}
217-
218177
private void configureRecipes(ScanResult result, String className) {
219178
for (ClassInfo classInfo : result.getSubclasses(className)) {
220179
Class<?> recipeClass = classInfo.loadClass();
@@ -289,12 +248,6 @@ public Map<String, List<RecipeExample>> listRecipeExamples() {
289248
return recipeExamples;
290249
}
291250

292-
@Override
293-
public Set<License> listLicenses() {
294-
ensureScanned();
295-
return licenses;
296-
}
297-
298251
@Override
299252
public Map<String, List<Contributor>> listContributors() {
300253
ensureScanned();

rewrite-core/src/main/java/org/openrewrite/config/Environment.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.nio.file.Path;
3030
import java.util.*;
3131
import java.util.function.Function;
32-
import java.util.stream.Collectors;
3332

3433
import static java.util.Collections.emptyList;
3534
import static java.util.Comparator.comparingInt;
@@ -300,13 +299,6 @@ public List<NamedStyles> activateStyles(String... activeStyles) {
300299
return activateStyles(Arrays.asList(activeStyles));
301300
}
302301

303-
public Set<License> listLicenses() {
304-
return resourceLoaders.stream()
305-
.map(ResourceLoader::listLicenses)
306-
.flatMap(Collection::stream)
307-
.collect(Collectors.toSet());
308-
}
309-
310302
public Environment(Collection<? extends ResourceLoader> resourceLoaders) {
311303
this.resourceLoaders = resourceLoaders;
312304
this.dependencyResourceLoaders = emptyList();

rewrite-core/src/main/java/org/openrewrite/config/License.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

rewrite-core/src/main/java/org/openrewrite/config/ResourceLoader.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import org.openrewrite.Recipe;
2121
import org.openrewrite.style.NamedStyles;
2222

23-
import java.util.Collection;
24-
import java.util.List;
25-
import java.util.Map;
26-
import java.util.Set;
23+
import java.util.*;
2724

2825
public interface ResourceLoader {
2926

@@ -65,6 +62,4 @@ boolean includedIn(RecipeDetail... include) {
6562
Map<String, List<Contributor>> listContributors();
6663

6764
Map<String, List<RecipeExample>> listRecipeExamples();
68-
69-
Set<License> listLicenses();
7065
}

rewrite-core/src/main/java/org/openrewrite/config/YamlResourceLoader.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.time.Duration;
4040
import java.util.*;
4141
import java.util.function.Consumer;
42-
import java.util.stream.Collectors;
4342
import java.util.stream.Stream;
4443

4544
import static java.util.Collections.emptyList;
@@ -591,15 +590,6 @@ public Map<String, List<RecipeExample>> listRecipeExamples() {
591590
return recipeNameToExamples;
592591
}
593592

594-
@Override
595-
public Set<License> listLicenses() {
596-
return dependencyResourceLoaders.stream()
597-
.filter(loader -> this != loader)
598-
.map(ResourceLoader::listLicenses)
599-
.flatMap(Collection::stream)
600-
.collect(Collectors.toSet());
601-
}
602-
603593
@Override
604594
public Map<String, List<Contributor>> listContributors() {
605595
if (contributors == null) {

rewrite-core/src/test/java/org/openrewrite/config/EnvironmentTest.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)