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

Pom utils excludes for non-shipped dependencies #27907

Merged
merged 3 commits into from Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* Copyright (c) 2023, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -17,10 +17,14 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
Expand Down Expand Up @@ -71,18 +75,35 @@ public static Model updateDependecies(Model pomModel) {
public static Model updateDependencies(Model pomModel, Function<Dependency, Boolean> isFiltered) {
String m = "updateDependencies";

boolean didRemove = false;
boolean didChange = false;

Iterator<Dependency> deps = pomModel.getDependencies().iterator();
while (deps.hasNext()) {
Dependency dep = deps.next();
if (isFiltered.apply(dep)) {
deps.remove();
didRemove = true;
didChange = true;
} else if (hasExcludes(dep)) {
addTransitiveExcludes(dep);
didChange = true;
}
}

return (didRemove ? pomModel : null);
return (didChange ? pomModel : null);
}

/**
* @param dep
* @return
*/
private static boolean hasExcludes(Dependency dep) {

String depString = dep.getGroupId() + ':' + dep.getArtifactId() + ':' + dep.getVersion();

if (transitiveExcludes.containsKey(depString))
return true;

return false;
}

public static final String[] DEV_GROUPS = { "dev", "test" };
Expand All @@ -95,7 +116,39 @@ public static boolean isDevGroup(Dependency dep) {
return "dev".equals(groupId) || "test".equals(groupId);
}

// TODO: Why these???
public static void addTransitiveExcludes(Dependency dep) {

List exclusions = dep.getExclusions();
String depString = dep.getGroupId() + ':' + dep.getArtifactId() + ':' + dep.getVersion();
String artifactPath = transitiveExcludes.get(depString);
String exclusion[] = artifactPath.split(":");
Exclusion ex = new Exclusion();
ex.setGroupId(exclusion[0]);
ex.setArtifactId(exclusion[1]);
exclusions.add(ex);
}

//We will add a pom excludes fragment in each of these dependency sections - Proven these are NOT shipped
static Map<String, String> transitiveExcludes = new HashMap<String, String>() {
{
put("org.apache.openwebbeans:openwebbeans-ee-common:1.1.6", "javassist:javassist");
put("org.apache.openwebbeans:openwebbeans-impl:1.1.6", "javassist:javassist");
put("org.apache.openwebbeans:openwebbeans-jsf:1.1.6", "javassist:javassist");
put("org.apache.openwebbeans:openwebbeans-web:1.1.6", "javassist:javassist");
put("org.apache.openwebbeans:openwebbeans-ee:1.1.6", "javassist:javassist");
put("org.apache.openwebbeans:openwebbeans-ejb:1.1.6", "javassist:javassist");
put("javax.ejb:javax.ejb-api:3.2", "javax.transaction:javax.transaction-api");
put("javax.resource:javax.resource-api:1.7", "javax.transaction:javax.transaction-api");
put("org.jboss.weld:weld-osgi-bundle:2.4.8.Final", "org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec");
put("org.jboss.weld:weld-osgi-bundle:3.1.9.Final", "org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec");
put("org.jboss.weld:weld-osgi-bundle:5.1.1.SP1", "org.jboss.logging:jboss-logging-processor");
put("org.jboss.weld.se:weld-se-core:5.1.1.SP1", "org.jboss.logging:jboss-logging-processor");
put("org.apache.cxf:cxf-rt-rs-service-description:3.3.0", "org.jboss.spec.javax.rmi:jboss-rmi-api_1.0_spec");
put("org.apache.cxf:cxf-rt-rs-sse:3.3.0", "org.jboss.spec.javax.rmi:jboss-rmi-api_1.0_spec");
}
};

//We know we are not including these packages in our shipped jar's
public static final String[] FILTERED_GROUPS = { "org.springframework",
"org.springframework.boot",
"com.ibm.ws.common.encoder" };
Expand Down