use of org.eclipse.aether.RepositorySystemSession in project build-info by JFrogDev.
the class BuildInfoRecorderLifecycleParticipantTest method testParticipantImplementation.
public void testParticipantImplementation() throws Exception {
BuildInfoRecorder buildInfoRecorder = new BuildInfoRecorder();
BuildInfoRecorderLifecycleParticipant participant = new BuildInfoRecorderLifecycleParticipant();
Class<BuildInfoRecorderLifecycleParticipant> participantClass = BuildInfoRecorderLifecycleParticipant.class;
Field recorderField = participantClass.getDeclaredField("recorder");
recorderField.set(participant, buildInfoRecorder);
Field loggerField = participantClass.getDeclaredField("logger");
loggerField.setAccessible(true);
loggerField.set(participant, new AbstractLogger(1, "dummy") {
public void debug(String message, Throwable throwable) {
Assert.assertTrue(message.contains("value is true"));
}
public void info(String message, Throwable throwable) {
assert false;
}
public void warn(String message, Throwable throwable) {
assert false;
}
public void error(String message, Throwable throwable) {
assert false;
}
public void fatalError(String message, Throwable throwable) {
assert false;
}
public Logger getChildLogger(String name) {
assert false;
return null;
}
});
PlexusContainer plexusContainerMock = EasyMock.createMock(PlexusContainer.class);
RepositorySystemSession repositorySystemSession = EasyMock.createMock(RepositorySystemSession.class);
MavenExecutionRequest requestMock = EasyMock.createMock(MavenExecutionRequest.class);
Properties mockSessionProperties = new Properties();
mockSessionProperties.setProperty(BuildInfoConfigProperties.ACTIVATE_RECORDER, "true");
EasyMock.expect(requestMock.getSystemProperties()).andReturn(mockSessionProperties).once();
EasyMock.expect(requestMock.getUserProperties()).andReturn(mockSessionProperties).once();
AbstractExecutionListener existingListener = new AbstractExecutionListener();
EasyMock.expect(requestMock.getExecutionListener()).andReturn(existingListener).times(1);
EasyMock.expect(requestMock.getUserSettingsFile()).andReturn(null).once();
EasyMock.expect(requestMock.setExecutionListener(buildInfoRecorder)).andReturn(null).once();
EasyMock.replay(requestMock);
MavenExecutionResult resultMock = EasyMock.createMock(MavenExecutionResult.class);
MavenSession session = new MavenSession(plexusContainerMock, repositorySystemSession, requestMock, resultMock);
// value is true
participant.afterProjectsRead(session);
}
use of org.eclipse.aether.RepositorySystemSession in project revapi by revapi.
the class ArtifactResolver method makeRemoteOnly.
private RepositorySystemSession makeRemoteOnly(RepositorySystemSession session) {
return new AbstractForwardingRepositorySystemSession() {
@Override
protected RepositorySystemSession getSession() {
return session;
}
@Override
public WorkspaceReader getWorkspaceReader() {
return null;
}
@Override
public LocalRepositoryManager getLocalRepositoryManager() {
LocalRepositoryManager wrapped = session.getLocalRepositoryManager();
return new LocalRepositoryManager() {
@Override
public LocalRepository getRepository() {
return wrapped.getRepository();
}
@Override
public String getPathForLocalArtifact(Artifact artifact) {
return wrapped.getPathForLocalArtifact(artifact);
}
@Override
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return wrapped.getPathForRemoteArtifact(artifact, repository, context);
}
@Override
public String getPathForLocalMetadata(Metadata metadata) {
return wrapped.getPathForLocalMetadata(metadata);
}
@Override
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return wrapped.getPathForRemoteMetadata(metadata, repository, context);
}
@Override
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
return wrapped.find(session, request);
}
@Override
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
wrapped.add(session, request);
}
@Override
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
if (request.getRepository() == null) {
// local metadata request... the returned file must not be null but may not exist
// we exploit that to not include the locally built results
LocalMetadataResult ret = new LocalMetadataResult(request);
ret.setFile(new File("<faked-to-force-remote-only-resolution-of-artifacts>"));
return ret;
} else {
return wrapped.find(session, request);
}
}
@Override
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
wrapped.add(session, request);
}
};
}
};
}
use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.
the class MavenEmbedder method getProjectBuildingRequest.
ProjectBuildingRequest getProjectBuildingRequest() throws ComponentLookupException {
ProjectBuildingRequest projectBuildingRequest = this.mavenExecutionRequest.getProjectBuildingRequest();
projectBuildingRequest.setValidationLevel(this.mavenRequest.getValidationLevel());
RepositorySystemSession repositorySystemSession = componentProvider.getRepositorySystemSession(mavenExecutionRequest);
projectBuildingRequest.setRepositorySession(repositorySystemSession);
projectBuildingRequest.setProcessPlugins(this.mavenRequest.isProcessPlugins());
projectBuildingRequest.setResolveDependencies(this.mavenRequest.isResolveDependencies());
return projectBuildingRequest;
}
use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.
the class MavenRepository method resolveArtifact.
public Artifact resolveArtifact(String artifactName, boolean logUnresolvedArtifact) {
Artifact artifact = new DefaultArtifact(artifactName);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
for (RemoteRepository repo : remoteRepositoriesForRequest) {
artifactRequest.addRepository(repo);
}
RepositorySystemSession session = aether.getSession();
Object sessionChecks = null;
boolean isSnapshot = artifactName.endsWith("-SNAPSHOT");
if (artifactName.endsWith("-SNAPSHOT")) {
// ensure to always update snapshots
sessionChecks = session.getData().get(SESSION_CHECKS);
session.getData().set(SESSION_CHECKS, null);
}
try {
ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, artifactRequest);
return artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
if (logUnresolvedArtifact) {
if (log.isDebugEnabled()) {
log.debug("Unable to resolve artifact: " + artifactName, e);
} else {
log.warn("Unable to resolve artifact: " + artifactName);
}
}
return null;
} finally {
if (sessionChecks != null) {
session.getData().set(SESSION_CHECKS, sessionChecks);
}
}
}
use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.
the class MavenEmbedder method init.
void init() throws MavenEmbedderException {
try {
this.mavenExecutionRequest = this.buildMavenExecutionRequest(mavenRequest);
RepositorySystemSession rss = ((DefaultMaven) componentProvider.lookup(Maven.class)).newRepositorySession(mavenExecutionRequest);
mavenSession = new MavenSession(componentProvider.getPlexusContainer(), rss, mavenExecutionRequest, new DefaultMavenExecutionResult());
componentProvider.lookup(LegacySupport.class).setSession(mavenSession);
} catch (MavenEmbedderException e) {
log.error("Unable to build MavenEmbedder", e);
throw e;
} catch (ComponentLookupException e) {
log.error("Unable to build MavenEmbedder", e);
throw new MavenEmbedderException(e.getMessage(), e);
}
}
Aggregations