Skip to content

Commit

Permalink
Ensure EE has OS runtime dependencies [DI-91] (#1315)
Browse files Browse the repository at this point in the history
EE shades OS, therefore _should_ have no direct dependency on OS -
however, `hazelcast-enterprise-native-memory` does have such a
dependency on OS, which brings that dependency back into EE.

Re-scoping that dependency [to `provided` also means that it's not
resolved
transitively](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-scope),
which means that any dependents on `hazelcast-enterprise-native-memory`
_also_ need to explicitly depend on OS.

Changes:
- Update scope of `hazelcast-enterprise-native-memory`'s OS dependency
- Update `hazelcast-enterprise-native-memory`'s dependents with the same
- Add `enforcer` configuration to `hazelcast-enterprise` to catch this
next time
- Update `CheckEnterpriseDependenciesIT` test
- whitelist any `com.hazelcast` as these will be provided via shading,
rather than from a dependency as it appears to the test
   - refactor it & `CheckDependenciesIT` parent to tidy up

Fixes: [DI-91](https://hazelcast.atlassian.net/browse/DI-91)

Checklist:
- [ ] Send backports/forwardports if fix needs to be applied to
past/future releases

[DI-91]:
https://hazelcast.atlassian.net/browse/DI-91?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Łukasz Dziedziul <l.dziedziul@gmail.com>
Co-authored-by: Tomasz Gawęda <tomasz.gaweda@outlook.com>
GitOrigin-RevId: c4da739d1ce5287d41baad54ec82688f56a1a510
  • Loading branch information
3 people authored and actions-user committed Apr 19, 2024
1 parent 9fb2b3d commit 55326bb
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions hazelcast/src/test/java/com/hazelcast/osgi/CheckDependenciesIT.java
Expand Up @@ -21,8 +21,8 @@
import com.hazelcast.internal.nio.IOUtil;
import com.hazelcast.internal.util.StringUtil;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.HazelcastTestSupport;
import com.hazelcast.test.annotation.QuickTest;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
import org.junit.Test;
Expand All @@ -38,15 +38,13 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNull;

@RunWith(HazelcastParallelClassRunner.class)
@Category(QuickTest.class)
public class CheckDependenciesIT extends HazelcastTestSupport {


public class CheckDependenciesIT {
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
private static final String[] WHITELIST_PREFIXES = new String[]{
protected static final String[] WHITELIST_PREFIXES = new String[]{

// everything from the Java package is OK - it's part of the Java SE platform
"java.",
Expand Down Expand Up @@ -102,7 +100,7 @@ protected String getBundleName() {
return "Hazelcast(Core)";
}

protected Manifest getHazelcastManifest() throws IOException {
private Manifest getHazelcastManifest() throws IOException {
URL hazelcastAllManifestUrl = findHazelcastManifestURL();
InputStream inputStream = null;
try {
Expand All @@ -114,24 +112,13 @@ protected Manifest getHazelcastManifest() throws IOException {
}

private void checkImport(String name, String resolution) {
if ("optional".equals(resolution)) {
return;
if (!isWhitelisted(name)) {
assertEquals("Import " + name + " is not declared as optional", "optional", resolution);
}
if (isWhitelisted(name)) {
return;
}

fail("Import " + name + " is not declared as optional");
}

private boolean isWhitelisted(String name) {
String[] whitelistPrefixes = getWhitelistPrefixes();
for (String whitelistPrefix : whitelistPrefixes) {
if (name.startsWith(whitelistPrefix)) {
return true;
}
}
return false;
return StringUtils.startsWithAny(name, getWhitelistPrefixes());
}

private URL findHazelcastManifestURL() throws IOException {
Expand All @@ -142,16 +129,11 @@ private URL findHazelcastManifestURL() throws IOException {
URL url = resources.nextElement();
String urlString = url.toString();
if (isMatching(urlString)) {
if (matchedUrl == null) {
matchedUrl = url;
} else {
throw new AssertionError("Found multiple matching URLs: " + url + " and " + matchedUrl);
}
assertNull("Found multiple matching URLs: " + url + " and " + matchedUrl, matchedUrl);
matchedUrl = url;
}
}
if (matchedUrl == null) {
throw new AssertionError("Cannot find Hazelcast manifest");
}
assertNotNull("Cannot find Hazelcast manifest", matchedUrl);
return matchedUrl;
}

Expand Down

0 comments on commit 55326bb

Please sign in to comment.