Search in sources :

Example 1 with MavenEmbedder

use of org.kie.maven.integration.embedder.MavenEmbedder in project drools by kiegroup.

the class MavenRepository method getRemoteRepositoryFromDistributionManagement.

protected RemoteRepository getRemoteRepositoryFromDistributionManagement(File pomfile) {
    MavenProject mavenProject = parseMavenPom(pomfile);
    DistributionManagement distMan = mavenProject.getDistributionManagement();
    if (distMan == null) {
        return null;
    }
    DeploymentRepository deployRepo = distMan.getSnapshotRepository() != null && mavenProject.getVersion().endsWith("SNAPSHOT") ? distMan.getSnapshotRepository() : distMan.getRepository();
    if (deployRepo == null) {
        return null;
    }
    RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder(deployRepo.getId(), deployRepo.getLayout(), deployRepo.getUrl()).setSnapshotPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN)).setReleasePolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN));
    Server server = MavenSettings.getSettings().getServer(deployRepo.getId());
    if (server != null) {
        MavenEmbedder embedder = MavenProjectLoader.newMavenEmbedder(false);
        try {
            Authentication authentication = embedder.getMavenSession().getRepositorySession().getAuthenticationSelector().getAuthentication(remoteRepoBuilder.build());
            remoteRepoBuilder.setAuthentication(authentication);
        } finally {
            embedder.dispose();
        }
    }
    return remoteRepoBuilder.build();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Server(org.apache.maven.settings.Server) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) MavenEmbedder(org.kie.maven.integration.embedder.MavenEmbedder) Authentication(org.eclipse.aether.repository.Authentication) DeploymentRepository(org.apache.maven.model.DeploymentRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DistributionManagement(org.apache.maven.model.DistributionManagement)

Aggregations

DeploymentRepository (org.apache.maven.model.DeploymentRepository)1 DistributionManagement (org.apache.maven.model.DistributionManagement)1 MavenProject (org.apache.maven.project.MavenProject)1 Server (org.apache.maven.settings.Server)1 Authentication (org.eclipse.aether.repository.Authentication)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)1 MavenEmbedder (org.kie.maven.integration.embedder.MavenEmbedder)1