Search in sources :

Example 11 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository in project drools by kiegroup.

the class MavenRepositoryConfiguration method toArtifactRepository.

private ArtifactRepository toArtifactRepository(RemoteRepository remoteRepository) {
    final String id = remoteRepository.getId();
    final String url = remoteRepository.getUrl();
    final Proxy activeProxy = settings.getActiveProxy();
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy();
    ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy();
    if (remoteRepository.getPolicy(true) != null) {
        snapshots = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(true).isEnabled(), remoteRepository.getPolicy(true).getUpdatePolicy(), remoteRepository.getPolicy(true).getChecksumPolicy());
    }
    if (remoteRepository.getPolicy(false) != null) {
        releases = new ArtifactRepositoryPolicy(remoteRepository.getPolicy(false).isEnabled(), remoteRepository.getPolicy(false).getUpdatePolicy(), remoteRepository.getPolicy(false).getChecksumPolicy());
    }
    final ArtifactRepository artifactRepository = new MavenArtifactRepository(id, url, layout, snapshots, releases);
    final Server server = settings.getServer(id);
    if (server != null) {
        artifactRepository.setAuthentication(new Authentication(server.getUsername(), server.getPassword()));
    }
    if (activeProxy != null) {
        if (null == activeProxy.getNonProxyHosts()) {
            artifactRepository.setProxy(getActiveMavenProxyFromSettings(settings));
        } else if (!repositoryUrlMatchNonProxyHosts(settings.getActiveProxy().getNonProxyHosts(), artifactRepository.getUrl())) {
            artifactRepository.setProxy(getActiveMavenProxyFromSettings(settings));
        }
    }
    return artifactRepository;
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) Authentication(org.apache.maven.artifact.repository.Authentication) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository)

Example 12 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository in project docker-maven-plugin by fabric8io.

the class DockerFileUtilTest method mockMojoParams.

private MojoParameters mockMojoParams() {
    MavenProject project = new MavenProject();
    project.setArtifactId("docker-maven-plugin");
    Properties projectProperties = project.getProperties();
    projectProperties.put("base", "java");
    projectProperties.put("name", "guenther");
    projectProperties.put("age", "42");
    projectProperties.put("ext", "png");
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {

        public String getBasedir() {
            return "repository";
        }
    };
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date(System.currentTimeMillis()));
    // Maven CLI override: -DcliOverride=cliValue
    session.getUserProperties().setProperty("cliOverride", "cliValue");
    // Java system property: -Duser.name=somebody
    session.getSystemProperties().put("user.name", "somebody");
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Settings(org.apache.maven.settings.Settings)

Example 13 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method mockMojoParams.

private MojoParameters mockMojoParams(MavenProject project) {
    Settings settings = new Settings();
    ArtifactRepository localRepository = new MavenArtifactRepository() {

        @Mock
        public String getBasedir() {
            return "repository";
        }
    };
    @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
    return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) Settings(org.apache.maven.settings.Settings) Date(java.util.Date)

Example 14 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository in project maven-dependency-plugin by apache.

the class TestCopyDependenciesMojo2 method testRepositoryLayout.

public void testRepositoryLayout() throws Exception {
    String baseVersion = "2.0-SNAPSHOT";
    String groupId = "testGroupId";
    String artifactId = "expanded-snapshot";
    Artifact expandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "jar", null);
    mojo.getProject().getArtifacts().add(expandedSnapshot);
    mojo.getProject().getDependencyArtifacts().add(expandedSnapshot);
    Artifact pomExpandedSnapshot = createExpandedVersionArtifact(baseVersion, groupId, artifactId, "compile", "pom", null);
    mojo.getProject().getArtifacts().add(pomExpandedSnapshot);
    mojo.getProject().getDependencyArtifacts().add(pomExpandedSnapshot);
    mojo.useRepositoryLayout = true;
    mojo.execute();
    ArtifactFactory artifactFactory = lookup(ArtifactFactory.class);
    File outputDirectory = mojo.outputDirectory;
    ArtifactRepository targetRepository = new MavenArtifactRepository("local", outputDirectory.toURL().toExternalForm(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        assertArtifactExists(artifact, targetRepository);
        if (!artifact.getBaseVersion().equals(artifact.getVersion())) {
            Artifact baseArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getScope(), artifact.getType());
            assertArtifactExists(baseArtifact, targetRepository);
        }
    }
}
Also used : ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 15 with MavenArtifactRepository

use of org.apache.maven.artifact.repository.MavenArtifactRepository in project pom-manipulation-ext by release-engineering.

the class Cli method createSession.

private void createSession(File target, File settings) {
    try {
        PlexusContainer container = new DefaultPlexusContainer();
        pomIO = container.lookup(PomIO.class);
        session = container.lookup(ManipulationSession.class);
        manipulationManager = container.lookup(ManipulationManager.class);
        final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(System.getProperties()).setUserProperties(userProps).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
        ArtifactRepository ar = null;
        if (settings == null) {
            // No, this is not a typo. If current default is null, supply new local and global.
            // This function passes in settings to make it easier to test.
            this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml");
            ar = new MavenArtifactRepository();
            ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository");
            req.setLocalRepository(ar);
        }
        req.setUserSettingsFile(settings);
        req.setGlobalSettingsFile(settings);
        MavenExecutionRequestPopulator executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
        executionRequestPopulator.populateFromSettings(req, parseSettings(settings));
        executionRequestPopulator.populateDefaults(req);
        if (ar != null) {
            ar.setUrl("file://" + req.getLocalRepositoryPath());
        }
        if (userProps != null && userProps.containsKey("maven.repo.local")) {
            if (ar == null) {
                ar = new MavenArtifactRepository();
            }
            ar.setUrl("file://" + userProps.getProperty("maven.repo.local"));
            req.setLocalRepository(ar);
        }
        final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
        mavenSession.getRequest().setPom(target);
        session.setMavenSession(mavenSession);
    } catch (ComponentLookupException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (PlexusContainerException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (SettingsBuildingException e) {
        logger.debug("Caught problem parsing settings file ", e);
        System.err.println("Unable to parse settings.xml file");
        System.exit(100);
    } catch (MavenExecutionRequestPopulationException e) {
        logger.debug("Caught problem populating maven request from settings file ", e);
        System.err.println("Unable to create maven execution request from settings.xml file");
        System.exit(100);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationManager(org.commonjava.maven.ext.core.ManipulationManager) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomIO(org.commonjava.maven.ext.io.PomIO) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Aggregations

MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)18 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)17 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)14 File (java.io.File)6 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)6 MavenSession (org.apache.maven.execution.MavenSession)4 Settings (org.apache.maven.settings.Settings)4 Location (org.commonjava.maven.galley.model.Location)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Artifact (org.apache.maven.artifact.Artifact)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DefaultMirrorSelector (org.apache.maven.repository.DefaultMirrorSelector)2 Mirror (org.apache.maven.settings.Mirror)2 Profile (org.apache.maven.settings.Profile)2