Skip to content

Commit

Permalink
Transitive dependency projects are not discovered with --also-make
Browse files Browse the repository at this point in the history
Currently it can happen that if one selects a project with -pl / -am
this project has initially not any maven dependencies but then later on
tycho adds one as a dependency and then the one declared in the pom are
not found.

This now adds an additional step each time a project is added as a
dependency to look if that project also has maven dependencies that map
to reactor projects.
  • Loading branch information
laeubi committed Apr 27, 2024
1 parent 007d0fc commit 01aace7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Expand Up @@ -14,8 +14,6 @@

import java.nio.file.Path;

import org.codehaus.plexus.logging.Logger;

/**
* A generic representation of a workspace that is only initialized once and carries a cache key,
* belonging to a thread so it can be used in a threadsafe manner
Expand All @@ -28,14 +26,11 @@ public final class EclipseWorkspace<T> {

private T key;

private Logger logger;

private Thread thread;

EclipseWorkspace(Path workDir, T key, Logger logger, Thread thread) {
EclipseWorkspace(Path workDir, T key, Thread thread) {
this.workDir = workDir;
this.key = key;
this.logger = logger;
this.thread = thread;
}

Expand Down
Expand Up @@ -15,7 +15,10 @@
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.io.FileUtils;
Expand All @@ -32,7 +35,8 @@
@Component(role = EclipseWorkspaceManager.class)
public class EclipseWorkspaceManager implements Disposable {

private final Map<Thread, Map<Object, EclipseWorkspace<?>>> cache = new ConcurrentHashMap<>();
private final Map<Thread, Map<Object, EclipseWorkspace<?>>> cache = new WeakHashMap<>();
private final List<EclipseWorkspace<?>> toclean = new ArrayList<>();

@Requirement
private Logger logger;
Expand All @@ -45,30 +49,43 @@ public class EclipseWorkspaceManager implements Disposable {
@SuppressWarnings("unchecked")
public <T> EclipseWorkspace<T> getWorkspace(T key) {
Thread currentThread = Thread.currentThread();
return (EclipseWorkspace<T>) cache.computeIfAbsent(currentThread, t -> new ConcurrentHashMap<>())
.computeIfAbsent(key, x -> {
try {
return new EclipseWorkspace<>(Files.createTempDirectory("eclipseWorkspace"), key, logger,
currentThread);
} catch (IOException e) {
throw new IllegalStateException("can't create a temporary directory for the workspace!", e);
}
});
synchronized (cache) {
return (EclipseWorkspace<T>) cache.computeIfAbsent(currentThread, t -> new ConcurrentHashMap<>())
.computeIfAbsent(key, x -> {
try {
EclipseWorkspace<T> workspace = new EclipseWorkspace<>(
Files.createTempDirectory("eclipseWorkspace"), key, currentThread);
toclean.add(workspace);
return workspace;
} catch (IOException e) {
throw new IllegalStateException("can't create a temporary directory for the workspace!", e);
}
});
}
}

@Override
public void dispose() {
cache.values().forEach(map -> {
map.values().forEach(ws -> FileUtils.deleteQuietly(ws.getWorkDir().toFile()));
});
cache.clear();
for (EclipseWorkspace<?> workspace : toclean) {
FileUtils.deleteQuietly(workspace.getWorkDir().toFile());
}
}

/**
* Get a workspace that is unique for the given uri, current thread and mojo and therefore safe
* to be used in a maven multithread execution
*
* @param uri
* @param mojo
* @return an {@link EclipseWorkspace}
*/
public EclipseWorkspace<?> getWorkspace(URI uri, Mojo mojo) {
return getWorkspace(new MojoKey(uri.normalize(), mojo.getClass()));
return getWorkspace(new MojoKey(uri.normalize(), mojo.getClass().getName()));

}

private static final record MojoKey(URI uri, Class<?> clz) {
private static final record MojoKey(URI uri, String mojoClassName) {
//a key that uses the mojo class and a URI
}

Expand Down

0 comments on commit 01aace7

Please sign in to comment.