Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-17525042: RevAPI JPMS support. #173

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
05ffc29
W-17421329: Test Coverage for the RevAPI JPMS support.
IvanAndresFritzler Dec 16, 2024
2ba18a4
Self review
IvanAndresFritzler Dec 16, 2024
0ea563a
Self review
IvanAndresFritzler Dec 16, 2024
21219f3
W-17457827: JPMS support for the RevAPI plugin.
IvanAndresFritzler Dec 27, 2024
0d056e3
Initial support for reading annotations (jpms modules are now fully l…
IvanAndresFritzler Dec 27, 2024
0c8d789
Self review
IvanAndresFritzler Dec 27, 2024
e52d803
Refactor in order to move JPMS logic to the JPMS filter.
IvanAndresFritzler Dec 30, 2024
e214afc
Removing module layer generation and adding module system modes.
IvanAndresFritzler Jan 2, 2025
afa7f9b
Adding gus ticket to promotedApi pom
IvanAndresFritzler Jan 2, 2025
0e87ac5
Reverting revapi plugin version setup
IvanAndresFritzler Jan 2, 2025
64d5f38
Refactor that makes the JPMS validation use the RevApi APIs
IvanAndresFritzler Jan 15, 2025
8fee6e8
Code review
IvanAndresFritzler Jan 15, 2025
529ee71
More coverage
IvanAndresFritzler Jan 16, 2025
b4859e5
Looks like the cache is a problem after the refactor
IvanAndresFritzler Jan 20, 2025
42d8afd
Adding a feature to exclude export targets when the mode is jpms
IvanAndresFritzler Jan 22, 2025
4bac5a0
Automatic module detection
IvanAndresFritzler Jan 23, 2025
e20f9bc
Self review
IvanAndresFritzler Jan 23, 2025
9a939c7
Including open directives
IvanAndresFritzler Jan 28, 2025
f5ec9f4
Using MULE for tests until we have either an onboarded revapi fork or…
IvanAndresFritzler Jan 28, 2025
39fcfdd
Self review
IvanAndresFritzler Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 18 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>


<dependencies>
<dependency>
<groupId>org.mule.runtime</groupId>
Expand All @@ -133,11 +141,6 @@
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand All @@ -149,6 +152,16 @@
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/mule/tools/revapi/ApiBoundary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2023 Salesforce, Inc. All rights reserved.
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.tools.revapi;

import static java.util.Objects.requireNonNull;

import org.revapi.Element;
import org.revapi.java.spi.JavaTypeElement;

public interface ApiBoundary {

/**
* @param element The element that is going to be checked.
* @return True if the element is part of the API.
*/
default boolean isApi(Element<?> element) {
return isApi(findParentJavaTypeElement(element));
}

/**
* @param element The element that is going to be checked
* @return True if the element is part of the API.
*/
boolean isApi(JavaTypeElement element);

/**
* @return true if any valid call to {@link #isApi(Element)} or {@link #isApi(JavaTypeElement)} will return false.
*/
boolean isEmpty();

default String getPackageName(JavaTypeElement element) {
String canonicalName = element.getDeclaringElement().getQualifiedName().toString();
int index = canonicalName.lastIndexOf(".");
return canonicalName.substring(0, index);
}

/**
* Walks the {@link Element} hierarchy up in order to return the top parent {@link JavaTypeElement} found.
*
* @param element The element that will be walked.
* @return The top {@link JavaTypeElement} found.
* @throws IllegalStateException If no {@link JavaTypeElement} could be found.
*/
private static JavaTypeElement findParentJavaTypeElement(Element<?> element) {
requireNonNull(element, "Element must not be null.");
Element<?> typeElement = element;
while (typeElement != null
&& (!(typeElement instanceof JavaTypeElement) || typeElement.getParent() instanceof JavaTypeElement)) {
typeElement = typeElement.getParent();
}
if (typeElement == null) {
throw new IllegalStateException("Could not find the Java Type element for: " + element.getFullHumanReadableString());
}
return (JavaTypeElement) typeElement;
}

}
43 changes: 43 additions & 0 deletions src/main/java/org/mule/tools/revapi/CachedApiBoundary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Salesforce, Inc. All rights reserved.
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.tools.revapi;

import org.revapi.java.spi.JavaTypeElement;

import java.util.HashMap;
import java.util.Map;

public class CachedApiBoundary implements ApiBoundary {

private final ApiBoundary delegate;
private final Map<JavaTypeElement, Boolean> isApiCache = new HashMap<>();

public CachedApiBoundary(ApiBoundary delegate) {
this.delegate = delegate;
}

@Override
public boolean isApi(JavaTypeElement element) {
if (isApiCache.containsKey(element)) {
return isApiCache.get(element);
} else {
final boolean isApi = delegate.isApi(element);
isApiCache.put(element, isApi);
return isApi;
}
}

@Override
public boolean isEmpty() {
return delegate.isEmpty();
}

@Override
public String toString() {
return delegate.toString();
}
}
Loading