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;
}
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));
}
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));
}
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);
}
}
}
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);
}
}
Aggregations