use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DeployMojoTest method testDeployIfArtifactFileIsNull.
public void testDeployIfArtifactFileIsNull() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
MockitoAnnotations.initMocks(this);
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
setVariableValueToObject(mojo, "session", session);
assertNotNull(mojo);
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
artifact.setFile(null);
assertNull(artifact.getFile());
try {
mojo.execute();
fail("Did not throw mojo execution exception");
} catch (MojoExecutionException e) {
//expected
}
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DeployMojoTest method _testBasicDeployWithScpAsProtocol.
@Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.")
public void _testBasicDeployWithScpAsProtocol() throws Exception {
String originalUserHome = System.getProperty("user.home");
// FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
File altHome = new File(getBasedir(), "target/ssh-user-home");
altHome.mkdirs();
System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath());
Properties props = System.getProperties();
props.setProperty("user.home", altHome.getCanonicalPath());
System.setProperties(props);
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml");
mojo = (DeployMojo) lookupMojo("deploy", testPom);
assertNotNull(mojo);
ArtifactDeployerStub deployer = new ArtifactDeployerStub();
setVariableValueToObject(mojo, "deployer", deployer);
File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
assertTrue(file.exists());
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
artifact.setFile(file);
String altUserHome = System.getProperty("user.home");
if (altUserHome.equals(originalUserHome)) {
// this is *very* bad!
throw new IllegalStateException("Setting 'user.home' system property to alternate value did NOT work. Aborting test.");
}
File sshFile = new File(altUserHome, ".ssh");
System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());
//delete first the .ssh folder if existing before executing the mojo
if (sshFile.exists()) {
FileUtils.deleteDirectory(sshFile);
}
mojo.execute();
assertTrue(sshFile.exists());
FileUtils.deleteDirectory(sshFile);
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DeployMojoTest method testBasicDeploy.
public void testBasicDeploy() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
mojo = (DeployMojo) lookupMojo("deploy", testPom);
MockitoAnnotations.initMocks(this);
assertNotNull(mojo);
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
File file = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
assertTrue(file.exists());
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
artifact = (DeployArtifactStub) project.getArtifact();
String packaging = project.getPackaging();
assertEquals("jar", packaging);
artifact.setFile(file);
ArtifactRepositoryStub repo = getRepoStub(mojo);
assertNotNull(repo);
repo.setAppendToUrl("basic-deploy-test");
assertEquals("deploy-test", repo.getId());
assertEquals("deploy-test", repo.getKey());
assertEquals("file", repo.getProtocol());
assertEquals("file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl());
mojo.execute();
//check the artifact in local repository
List<String> expectedFiles = new ArrayList<String>();
List<String> fileList = new ArrayList<String>();
expectedFiles.add("org");
expectedFiles.add("apache");
expectedFiles.add("maven");
expectedFiles.add("test");
expectedFiles.add("maven-deploy-test");
expectedFiles.add("1.0-SNAPSHOT");
expectedFiles.add("maven-metadata-deploy-test.xml");
// expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
// expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
// as we are in SNAPSHOT the file is here twice
expectedFiles.add("maven-metadata-deploy-test.xml");
// extra Aether files
expectedFiles.add("resolver-status.properties");
expectedFiles.add("resolver-status.properties");
File localRepo = new File(LOCAL_REPO, "");
File[] files = localRepo.listFiles();
for (File file2 : files) {
addFileToList(file2, fileList);
}
assertEquals(expectedFiles.size(), fileList.size());
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
//check the artifact in remote repository
expectedFiles = new ArrayList<String>();
fileList = new ArrayList<String>();
expectedFiles.add("org");
expectedFiles.add("apache");
expectedFiles.add("maven");
expectedFiles.add("test");
expectedFiles.add("maven-deploy-test");
expectedFiles.add("1.0-SNAPSHOT");
expectedFiles.add("maven-metadata.xml");
expectedFiles.add("maven-metadata.xml.md5");
expectedFiles.add("maven-metadata.xml.sha1");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.md5");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.jar.sha1");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
// as we are in SNAPSHOT the file is here twice
expectedFiles.add("maven-metadata.xml");
expectedFiles.add("maven-metadata.xml.md5");
expectedFiles.add("maven-metadata.xml.sha1");
remoteRepo = new File(remoteRepo, "basic-deploy-test");
files = remoteRepo.listFiles();
for (File file1 : files) {
addFileToList(file1, fileList);
}
assertEquals(expectedFiles.size(), fileList.size());
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DoapMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
if (skip) {
getLog().info("Skipping DOAP generation");
return;
}
// single artifact
if (artifact != null) {
MavenProject givenProject = getMavenProject(artifact);
if (givenProject != null) {
File outDir = new File(outputDirectory);
if (!outDir.isAbsolute()) {
outDir = new File(project.getBasedir(), outputDirectory);
}
File outFile = new File(outDir, artifact.getDoapFileName());
writeDoapFile(givenProject, outFile);
return;
}
}
// current project
File outFile = new File(doapFile);
if (!outFile.isAbsolute()) {
outFile = new File(project.getBasedir(), doapFile);
}
if (!doapFile.replaceAll("\\\\", "/").contains("/")) {
File outDir = new File(outputDirectory);
if (!outDir.isAbsolute()) {
outDir = new File(project.getBasedir(), outputDirectory);
}
outFile = new File(outDir, doapFile);
}
writeDoapFile(project, outFile);
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DoapMojoTest method testGeneratedDoapArtifactMinimalist.
/**
* Verify the generation of a DOAP file from a minimalist artifact.
*
* @throws Exception if any
*/
public void testGeneratedDoapArtifactMinimalist() throws Exception {
File pluginXmlFile = new File(getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml");
DoapMojo mojo = (DoapMojo) lookupMojo("generate", pluginXmlFile);
assertNotNull("Mojo found.", mojo);
MavenProject mavenProject = (MavenProject) getVariableValueFromObject(mojo, "project");
assertNotNull(mavenProject);
// Set some Mojo parameters
setVariableValueToObject(mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories());
setVariableValueToObject(mojo, "about", "foo");
DoapOptions doapOptions = new DoapOptions();
doapOptions.setName("XStream");
doapOptions.setDescription("XStream is a simple library to serialize objects to XML and back again.");
doapOptions.setShortdesc("XML Serializer");
doapOptions.setHomepage("http://xstream.codehaus.org/");
doapOptions.setDownloadPage("http://xstream.codehaus.org/download.html");
doapOptions.setBugDatabase("http://jira.codehaus.org/browse/XSTR");
doapOptions.setLicense("http://xstream.codehaus.org/license.html");
doapOptions.setScmDeveloper("http://svn.codehaus.org/xstream/trunk/xstream");
doapOptions.setMailingList("http://xstream.codehaus.org/list-user.html");
doapOptions.setCreated("2000-01-01");
setVariableValueToObject(mojo, "doapOptions", doapOptions);
DoapArtifact artifact = new DoapArtifact();
artifact.setGroupId("xstream");
artifact.setArtifactId("xstream");
artifact.setVersion("1.1");
setVariableValueToObject(mojo, "artifact", artifact);
setVariableValueToObject(mojo, "outputDirectory", "target/test/unit/doap-configuration/");
mojo.execute();
File doapFile = new File(getBasedir(), "target/test/unit/doap-configuration/doap_xstream.rdf");
assertTrue("Doap File was not generated!", doapFile.exists());
String readed = readFile(doapFile);
// Validate
// Pure DOAP
assertTrue(readed.contains("<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" " + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">"));
assertTrue(readed.contains("<Project>"));
assertTrue(readed.contains("<name>XStream</name>"));
assertTrue(readed.contains("<description xml:lang=\"en\">XStream is a simple library to serialize objects to XML and back again.</description>"));
assertTrue(readed.contains("<shortdesc xml:lang=\"en\">XML Serializer</shortdesc>"));
assertTrue(readed.contains("<created>2000-01-01</created>"));
assertTrue(readed.contains("<download-page rdf:resource=\"http://xstream.codehaus.org/download.html\"/>"));
assertTrue(readed.contains("<programming-language>Java</programming-language>"));
assertTrue(readed.contains("<bug-database rdf:resource=\"http://jira.codehaus.org/browse/XSTR\"/>"));
assertTrue(readed.contains("<license rdf:resource=\"http://xstream.codehaus.org/license.html\"/>"));
assertTrue(readed.contains("<Repository>"));
assertTrue(readed.contains("<location rdf:resource=\"http://svn.codehaus.org/xstream/trunk/xstream\"/>"));
assertTrue(readed.contains("<mailing-list rdf:resource=\"http://xstream.codehaus.org/list-user.html\"/>"));
// conf
assertFalse(readed.contains("<audience>"));
assertFalse(readed.contains("<blog rdf:resource="));
assertFalse(readed.contains("<implements>"));
assertFalse(readed.contains("<language>"));
assertFalse(readed.contains("<old-homepage rdf:resource="));
assertFalse(readed.contains("<os>"));
assertFalse(readed.contains("<platform>"));
assertFalse(readed.contains("<screenshots rdf:resource="));
assertFalse(readed.contains("<service-endpoint rdf:resource="));
assertFalse(readed.contains("<wiki rdf:resource="));
}
Aggregations