-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a `Lookup` on context to be able to reach some Resolver components. Add demo doing it as well (and demo runs with "static" and "sisu" standalone runtimes, but also embedded in maven as "maven-plugin"). Fixes #94
- Loading branch information
Showing
14 changed files
with
749 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
context/src/main/java/eu/maveniverse/maven/mima/context/Lookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package eu.maveniverse.maven.mima.context; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* A simple "lookup" that allows to lookup various components. Lookup shares lifecycle with {@link Context}. | ||
* <p> | ||
* Note: this component offers access to Resolver internals, but it is up to caller to know really how to use | ||
* this feature (for example due compatibility reasons). Ideally, you do not want to use this, or use it only | ||
* in some "advanced scenarios". | ||
* | ||
* @since 2.4.10 | ||
*/ | ||
public interface Lookup { | ||
/** | ||
* Performs lookup for component with passed in type, and returns it as optional, never {@code null}. | ||
*/ | ||
<T> Optional<T> lookup(Class<T> type); | ||
|
||
/** | ||
* Performs lookup for component with passed in type and name, and returns it as optional, never {@code null}. | ||
*/ | ||
<T> Optional<T> lookup(Class<T> type, String name); | ||
} |
46 changes: 46 additions & 0 deletions
46
context/src/main/java/eu/maveniverse/maven/mima/context/internal/IteratingLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package eu.maveniverse.maven.mima.context.internal; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import eu.maveniverse.maven.mima.context.Lookup; | ||
import java.util.*; | ||
|
||
/** | ||
* A {@link Lookup} implementation that is able to iterate through several lookups, applying "first deliver wins" | ||
* strategy. | ||
* | ||
* @since 2.4.10 | ||
*/ | ||
public final class IteratingLookup implements Lookup { | ||
private final Collection<Lookup> lookups; | ||
|
||
public IteratingLookup(Lookup... lookups) { | ||
this(Arrays.asList(lookups)); | ||
} | ||
|
||
public IteratingLookup(Collection<Lookup> lookups) { | ||
this.lookups = requireNonNull(lookups); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> lookup(Class<T> type) { | ||
for (Lookup lookup : lookups) { | ||
Optional<T> result = lookup.lookup(type); | ||
if (result.isPresent()) { | ||
return result; | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> lookup(Class<T> type, String name) { | ||
for (Lookup lookup : lookups) { | ||
Optional<T> result = lookup.lookup(type, name); | ||
if (result.isPresent()) { | ||
return result; | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ed-maven/src/main/java/eu/maveniverse/maven/mima/runtime/maven/internal/PlexusLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package eu.maveniverse.maven.mima.runtime.maven.internal; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import eu.maveniverse.maven.mima.context.Lookup; | ||
import java.util.Optional; | ||
import org.codehaus.plexus.PlexusContainer; | ||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | ||
|
||
public final class PlexusLookup implements Lookup { | ||
private final PlexusContainer plexusContainer; | ||
|
||
public PlexusLookup(PlexusContainer plexusContainer) { | ||
this.plexusContainer = requireNonNull(plexusContainer); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> lookup(Class<T> type) { | ||
try { | ||
return Optional.of(plexusContainer.lookup(type)); | ||
} catch (ComponentLookupException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> lookup(Class<T> type, String name) { | ||
try { | ||
return Optional.of(plexusContainer.lookup(type, name)); | ||
} catch (ComponentLookupException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.