use of org.eclipse.aether.repository.LocalRepository in project meecrowave by apache.
the class MeecrowaveBundleMojoTest method bundle.
@Test
public void bundle() throws Exception {
final File moduleBase = jarLocation(MeecrowaveBundleMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final Build build = new Build();
final File buildDir = new File("target/" + getClass().getName() + "/build");
build.setDirectory(buildDir.getAbsolutePath());
project.setBuild(build);
final MavenSession session = mojo.newMavenSession(project);
final MojoExecution execution = mojo.newMojoExecution("bundle");
execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("conf") {
{
setValue("src/main/meecrowave/conf");
}
});
execution.getConfiguration().addChild(new Xpp3Dom("webapp") {
{
setValue("src/main/webapp");
}
});
mojo.executeMojo(session, project, execution);
assertTrue(buildDir.exists());
try (final ZipFile zip = new ZipFile(new File(buildDir, "test-meecrowave-distribution.zip"))) {
assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
}
}
use of org.eclipse.aether.repository.LocalRepository in project camel by apache.
the class BOMResolver method retrieveUpstreamBOMVersions.
private void retrieveUpstreamBOMVersions() throws Exception {
RepositorySystem system = newRepositorySystem();
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(LOCAL_REPO);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
String camelVersion = DependencyResolver.resolveCamelParentProperty("${project.version}");
List<Artifact> neededArtifacts = new LinkedList<>();
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel:pom:" + camelVersion).setFile(camelRoot("pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-parent:pom:" + camelVersion).setFile(camelRoot("parent/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:spring-boot:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dm:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/pom.xml")));
neededArtifacts.add(new DefaultArtifact("org.apache.camel:camel-spring-boot-dependencies:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml")));
Artifact camelSpringBootParent = new DefaultArtifact("org.apache.camel:camel-starter-parent:pom:" + camelVersion).setFile(camelRoot("platforms/spring-boot/spring-boot-dm/camel-starter-parent/pom.xml"));
neededArtifacts.add(camelSpringBootParent);
RemoteRepository localRepoDist = new RemoteRepository.Builder("org.apache.camel.itest.springboot", "default", new File(LOCAL_REPO).toURI().toString()).build();
for (Artifact artifact : neededArtifacts) {
DeployRequest deployRequest = new DeployRequest();
deployRequest.addArtifact(artifact);
deployRequest.setRepository(localRepoDist);
system.deploy(session, deployRequest);
}
RemoteRepository mavenCentral = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build();
ArtifactDescriptorRequest dReq = new ArtifactDescriptorRequest(camelSpringBootParent, Arrays.asList(localRepoDist, mavenCentral), null);
ArtifactDescriptorResult dRes = system.readArtifactDescriptor(session, dReq);
this.versions = new TreeMap<>();
for (Dependency dependency : dRes.getManagedDependencies()) {
Artifact a = dependency.getArtifact();
String key = a.getGroupId() + ":" + a.getArtifactId();
versions.put(key, dependency.getArtifact().getVersion());
}
}
use of org.eclipse.aether.repository.LocalRepository in project bnd by bndtools.
the class AetherRepository method init.
protected final synchronized void init() throws Exception {
if (initialised)
return;
// Initialise Aether
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
locator.setErrorHandler(new ErrorHandler() {
@Override
public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
if (reporter != null)
reporter.error("Service creation failed for type %s using impl %s: %s", type, impl, exception.getLocalizedMessage());
exception.printStackTrace();
}
});
repoSystem = locator.getService(RepositorySystem.class);
if (repoSystem == null)
throw new IllegalArgumentException("Failed to initialise Aether repository system");
Builder builder = new RemoteRepository.Builder("remote", "default", mainUri.toString());
if (username != null) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder().addUsername(username);
if (password != null)
authBuilder.addPassword(password);
builder.setAuthentication(authBuilder.build());
}
remoteRepo = builder.build();
localRepo = new LocalRepository(new File(cacheDir, "aether-local"));
// Initialise Index
if (indexUri == null) {
indexedRepo = null;
} else {
// Test whether the index URI exists and is available.
HttpURLConnection connection = (HttpURLConnection) indexUri.toURL().openConnection();
try {
connection.setRequestMethod("HEAD");
int responseCode = connection.getResponseCode();
if (responseCode >= 400) {
indexedRepo = null;
} else {
indexedRepo = new FixedIndexedRepo();
Map<String, String> config = new HashMap<String, String>();
indexedRepo.setReporter(this.reporter);
indexedRepo.setRegistry(registry);
config.put(FixedIndexedRepo.PROP_CACHE, cacheDir.getAbsolutePath());
config.put(FixedIndexedRepo.PROP_LOCATIONS, indexUri.toString());
indexedRepo.setProperties(config);
}
} catch (UnknownHostException e) {
return;
} finally {
connection.disconnect();
}
}
initialised = true;
}
use of org.eclipse.aether.repository.LocalRepository in project meecrowave by apache.
the class MeecrowaveRunMojoTest method run.
@Test
public void run() throws Exception {
final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final MavenSession session = mojo.newMavenSession(project);
final int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
final MojoExecution execution = mojo.newMojoExecution("run");
execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {
{
setValue(Integer.toString(port));
}
});
final InputStream in = System.in;
final CountDownLatch latch = new CountDownLatch(1);
System.setIn(new InputStream() {
// just to not return nothing
private int val = 2;
@Override
public int read() throws IOException {
try {
latch.await();
} catch (final InterruptedException e) {
Thread.interrupted();
fail(e.getMessage());
}
return val--;
}
});
final Thread runner = new Thread() {
@Override
public void run() {
try {
mojo.executeMojo(session, project, execution);
} catch (final Exception e) {
fail(e.getMessage());
}
}
};
try {
runner.start();
for (int i = 0; i < 120; i++) {
try {
assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Thread.sleep(500);
}
}
} finally {
runner.join(TimeUnit.MINUTES.toMillis(1));
System.setIn(in);
if (runner.isAlive()) {
runner.interrupt();
fail("Runner didn't terminate properly");
}
}
}
use of org.eclipse.aether.repository.LocalRepository in project embulk by embulk.
the class MavenArtifactFinder method createRepositorySystemSession.
private static RepositorySystemSession createRepositorySystemSession(final RepositorySystem repositorySystem, final Path localRepositoryPath) {
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
final LocalRepository repository = new LocalRepository(localRepositoryPath.toString());
session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, repository));
return session;
}
Aggregations