Search in sources :

Example 21 with LocalRepository

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);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) ZipFile(java.util.zip.ZipFile) MojoExecution(org.apache.maven.plugin.MojoExecution) Build(org.apache.maven.model.Build) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 22 with LocalRepository

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());
    }
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) LinkedList(java.util.LinkedList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest)

Example 23 with LocalRepository

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;
}
Also used : ErrorHandler(org.eclipse.aether.impl.DefaultServiceLocator.ErrorHandler) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) RepositorySystem(org.eclipse.aether.RepositorySystem) HttpURLConnection(java.net.HttpURLConnection) File(java.io.File) FixedIndexedRepo(aQute.bnd.deployer.repository.FixedIndexedRepo)

Example 24 with LocalRepository

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");
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) InputStream(java.io.InputStream) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) URL(java.net.URL) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) File(java.io.File) Test(org.junit.Test)

Example 25 with LocalRepository

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;
}
Also used : DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LocalRepository(org.eclipse.aether.repository.LocalRepository)

Aggregations

LocalRepository (org.eclipse.aether.repository.LocalRepository)42 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)34 File (java.io.File)15 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 RepositorySystem (org.eclipse.aether.RepositorySystem)6 JarFile (java.util.jar.JarFile)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 SimpleLocalRepositoryManagerFactory (org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory)5 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)5 MalformedURLException (java.net.MalformedURLException)4 LinkedList (java.util.LinkedList)4 Artifact (org.eclipse.aether.artifact.Artifact)4 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)4 URL (java.net.URL)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 VersionConstraint (org.eclipse.aether.version.VersionConstraint)3