use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class TestUnpackMojo method setUp.
protected void setUp() throws Exception {
super.setUp("unpack", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
mojo = (UnpackMojo) lookupMojo("unpack", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
mojo.setMarkersDirectory(new File(this.testDir, "markers"));
mojo.setSilent(true);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
// MavenProject project = mojo.getProject();
// init classifier things
// it needs to get the archivermanager
stubFactory.setUnpackableFile(mojo.getArchiverManager());
// i'm using one file repeatedly to archive so I can test the name
// programmatically.
stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + "target/test-classes/unit/unpack-dependencies-test/test.txt"));
mojo.setUseJvmChmod(true);
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class TestCopyDependenciesMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class TestCopyMojo method setUp.
protected void setUp() throws Exception {
super.setUp("copy", false, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml");
mojo = (CopyMojo) lookupMojo("copy", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
mojo.setSilent(true);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
// MavenProject project = mojo.getProject();
// init classifier things
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class InstallMojoTest method createMavenSession.
private MavenSession createMavenSession() {
MavenSession session = mock(MavenSession.class);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManager(new File(LOCAL_REPO)));
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
buildingRequest.setRepositorySession(repositorySession);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
return session;
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class InstallMojoTest method testBasicInstallAndCreateChecksumIsTrue.
public void testBasicInstallAndCreateChecksumIsTrue() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
assertNotNull(mojo);
File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
MavenSession mavenSession = createMavenSession();
updateMavenProject(project);
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
setVariableValueToObject(mojo, "session", mavenSession);
artifact = (InstallArtifactStub) project.getArtifact();
boolean createChecksum = (Boolean) getVariableValueFromObject(mojo, "createChecksum");
assertTrue(createChecksum);
artifact.setFile(file);
mojo.execute();
ArtifactMetadata metadata = null;
for (Object o : artifact.getMetadataList()) {
metadata = (ArtifactMetadata) o;
if (metadata.getRemoteFilename().endsWith("pom")) {
break;
}
}
RepositoryManager repoManager = (RepositoryManager) getVariableValueFromObject(mojo, "repositoryManager");
ProjectBuildingRequest pbr = mavenSession.getProjectBuildingRequest();
File pom = new File(repoManager.getLocalRepositoryBasedir(pbr), repoManager.getPathForLocalMetadata(pbr, metadata));
assertTrue(pom.exists());
String groupId = dotToSlashReplacer(artifact.getGroupId());
String packaging = project.getPackaging();
String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
// get the actual checksum of the pom
Map<String, Object> csums = ChecksumUtils.calc(pom, Utils.CHECKSUM_ALGORITHMS);
for (Map.Entry<String, Object> csum : csums.entrySet()) {
Object actualPomSum = csum.getValue();
File pomSum = new File(localPath + ".pom." + csum.getKey().toLowerCase().replace("-", ""));
assertTrue(pomSum.exists());
String generatedPomSum = FileUtils.fileRead(pomSum, "UTF-8");
assertEquals(actualPomSum, generatedPomSum);
}
// get the actual checksum of the artifact
csums = ChecksumUtils.calc(file, Utils.CHECKSUM_ALGORITHMS);
for (Map.Entry<String, Object> csum : csums.entrySet()) {
Object actualSum = csum.getValue();
File sum = new File(localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace("-", ""));
assertTrue(sum.exists());
String generatedSum = FileUtils.fileRead(sum, "UTF-8");
assertEquals(actualSum, generatedSum);
}
File installedArtifact = new File(localPath + "." + packaging);
assertTrue(installedArtifact.exists());
assertEquals(9, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Aggregations