use of org.sonatype.aether.util.DefaultRepositorySystemSession in project sonatype-aether by sonatype.
the class AsyncHandlerExceptionTest method testIt.
@Test
public void testIt() throws Exception {
HttpServer server = new HttpServer();
server.addResources("/", baseDir.getAbsolutePath());
server.start();
try {
RemoteRepository repo = new RemoteRepository("id", "default", server.getHttpUrl() + "/repo");
RepositorySystemSession session = new DefaultRepositorySystemSession();
AsyncRepositoryConnector connector = new AsyncRepositoryConnector(repo, session, new TestFileProcessor(), new SysoutLogger());
try {
StubArtifact artifact = new StubArtifact("gid:aid:1.0");
for (int i = 0; i < 16; i++) {
System.out.println("RUN #" + i);
TestFileUtils.delete(baseDir);
ArtifactDownload download = new ArtifactDownload(artifact, "project", new File(baseDir, "a.jar"), "ignore");
System.out.println("GET");
connector.get(Arrays.asList(download), null);
assertTrue(String.valueOf(download.getException()), download.getException() instanceof ArtifactNotFoundException);
ArtifactUpload upload = new ArtifactUpload(artifact, new File("pom.xml"));
System.out.println("PUT");
connector.put(Arrays.asList(upload), null);
if (upload.getException() != null) {
upload.getException().printStackTrace();
}
assertNull(String.valueOf(upload.getException()), upload.getException());
}
} finally {
connector.close();
}
} finally {
server.stop();
}
}
use of org.sonatype.aether.util.DefaultRepositorySystemSession in project gradle by gradle.
the class MavenProjectsCreator method createNow.
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, PlexusConfigurationException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", ClassWorld.class.getClassLoader())).setName("mavenCore");
DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
ProjectBuilder builder = container.lookup(ProjectBuilder.class);
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final Properties properties = new Properties();
properties.putAll(SystemProperties.getInstance().asMap());
executionRequest.setSystemProperties(properties);
MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
populator.populateFromSettings(executionRequest, settings);
populator.populateDefaults(executionRequest);
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.setProcessPlugins(false);
MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
Set<MavenProject> reactorProjects = new LinkedHashSet<MavenProject>();
//TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
//the converter should not depend on the order of reactor projects.
//we should add coverage for nested multi-project builds with multiple parents.
reactorProjects.add(mavenProject);
List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
CollectionUtils.collect(allProjects, reactorProjects, new Transformer<MavenProject, ProjectBuildingResult>() {
public MavenProject transform(ProjectBuildingResult original) {
return original.getProject();
}
});
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setProject(mavenProject);
RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
session.setCurrentProject(mavenProject);
return reactorProjects;
}
use of org.sonatype.aether.util.DefaultRepositorySystemSession in project karaf by apache.
the class Dependency30Helper method getDependencyTree.
private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
try {
CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
return result.getRoot();
} catch (DependencyCollectionException e) {
throw new MojoExecutionException("Cannot build project dependency tree", e);
}
}
use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.
the class TestIncludeExcludeUnpackMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
mojo = (UnpackMojo) lookupMojo("unpack", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
// mojo.silent = true;
// it needs to get the archivermanager
//stubFactory.setUnpackableFile( mojo.getArchiverManager() );
// i'm using one file repeatedly to archive so I can test the name
// programmatically.
stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
ArtifactItem item = stubFactory.getArtifactItem(artifact);
List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
list.add(item);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
mojo.setMarkersDirectory(new File(this.testDir, "markers"));
mojo.setArtifactItems(list);
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.
the class TestClassifierTypeTranslator method setUp.
protected void setUp() throws Exception {
super.setUp("classifiertype-translator", false);
artifactHandlerManager = new DefaultArtifactHandlerManager();
this.setVariableValueToObject(artifactHandlerManager, "artifactHandlers", new HashMap());
artifactFactory = new DefaultArtifactFactory();
this.setVariableValueToObject(artifactFactory, "artifactHandlerManager", artifactHandlerManager);
artifactRepository = new StubArtifactRepository(null);
DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory(null, false);
artifacts = factory.getMixedArtifacts();
repoManager = lookup(RepositoryManager.class);
MavenSession session = newMavenSession(new MavenProjectStub());
buildingRequest = session.getProjectBuildingRequest();
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Aggregations