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

Support Maven 4 at runtime, fixes #72 #73

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/main/java/kr/motd/maven/os/RepositorySessionInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -32,8 +34,27 @@ static void injectRepositorySession(
final Field f = cls.getDeclaredField("systemProperties");
f.setAccessible(true);
repoSessionProps = (Map<String, String>) f.get(repoSession);
for (Map.Entry<String, String> e : dict.entrySet()) {
repoSessionProps.put(e.getKey(), e.getValue());
try {
for (Map.Entry<String, String> e : dict.entrySet()) {
repoSessionProps.put(e.getKey(), e.getValue());
}
} catch (Exception ex2) {
// In Maven 4, DefaultCloseableSession uses an immutable map
// but DefaultRepositorySystemSession may also have an immutable map
repoSessionProps = new HashMap<>(repoSessionProps);
for (Map.Entry<String, String> e : dict.entrySet()) {
repoSessionProps.put(e.getKey(), e.getValue());
}
repoSessionProps = Collections.unmodifiableMap(repoSessionProps);
f.set(repoSession, repoSessionProps);
try {
// This is to support DefaultRepositorySystemSession
final Field fv = cls.getDeclaredField("systemPropertiesView");
fv.setAccessible(true);
fv.set(repoSession, repoSessionProps);
} catch (Exception ex3) {
// ignore
}
}
}
} catch (Throwable t) {
Expand Down