use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AbstractDeployMojo method getTopLevelProject.
/**
* Extract the distributionManagement site of the top level parent of the given MavenProject.
* This climbs up the project hierarchy and returns the site of the last project
* for which {@link #getSite(org.apache.maven.project.MavenProject)} returns a site that resides in the
* same site. Notice that it doesn't take into account if the parent is in the reactor or not.
*
* @param project the MavenProject. Not <code>null</code>.
* @return the top level site. Not <code>null</code>.
* Also site.getUrl() and site.getId() are guaranteed to be not <code>null</code>.
* @throws MojoExecutionException if no site info is found in the tree.
* @see URIPathDescriptor#sameSite(java.net.URI)
*/
protected MavenProject getTopLevelProject(MavenProject project) throws MojoExecutionException {
Site site = getSite(project);
MavenProject parent = project;
while (parent.getParent() != null) {
MavenProject oldProject = parent;
// MSITE-585, MNG-1943
parent = siteTool.getParentProject(parent, reactorProjects, localRepository);
Site oldSite = site;
try {
site = getSite(parent);
} catch (MojoExecutionException e) {
return oldProject;
}
// MSITE-600
URIPathDescriptor siteURI = new URIPathDescriptor(URIEncoder.encodeURI(site.getUrl()), "");
URIPathDescriptor oldSiteURI = new URIPathDescriptor(URIEncoder.encodeURI(oldSite.getUrl()), "");
if (!siteURI.sameSite(oldSiteURI.getBaseURI())) {
return oldProject;
}
}
return parent;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class SiteStageDeployMojo method getTopMostParentWithSameStagingSiteURL.
/**
* Extract the distributionManagement.site of the top most project in the
* hierarchy that specifies a stagingSiteURL, starting at the actual MavenProject.
* <p/>
* This climbs up the project hierarchy and returns the site of the top most
* project for which
* {@link #getStagingSiteURL(org.apache.maven.project.MavenProject)} returns
* same URL as actual.
*
* @return the site for the top most project that has a stagingSiteURL. Not null.
*/
private MavenProject getTopMostParentWithSameStagingSiteURL() {
MavenProject current = project;
MavenProject parent;
// CHECKSTYLE_OFF: InnerAssignment
while (// MSITE-585, MNG-1943
(parent = siteTool.getParentProject(current, reactorProjects, localRepository)) != null && stagingSiteURL.equals(getStagingSiteURL(parent))) {
current = parent;
}
return current;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AbstractStagingMojo method determineTopDistributionManagementSiteUrl.
/**
* By default, staging mojos will get their top distribution management site url by getting top parent
* with the same site, which is a good heuristics. But in case the default value doesn't match
* expectations, <code>topSiteURL</code> can be configured: it will be used instead.
*/
@Override
protected String determineTopDistributionManagementSiteUrl() throws MojoExecutionException {
if (StringUtils.isEmpty(topSiteURL)) {
MavenProject topProject = getTopLevelProject(project);
String url = getSite(topProject).getUrl();
getLog().debug("staging top distributionManagement.site.url found in " + topProject.getId() + " with value: " + url);
return url;
}
getLog().debug("staging top distributionManagement.site.url configured with topSiteURL parameter: " + topSiteURL);
return topSiteURL;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AntRunMojo method execute.
/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
checkDeprecatedParameterUsage(tasks, "tasks", "target");
checkDeprecatedParameterUsage(sourceRoot, "sourceRoot", "the build-helper-maven-plugin");
checkDeprecatedParameterUsage(testSourceRoot, "testSourceRoot", "the build-helper-maven-plugin");
if (skip) {
getLog().info("Skipping Antrun execution");
return;
}
MavenProject mavenProject = getMavenProject();
if (target == null) {
getLog().info("No Ant target defined - SKIPPED");
return;
}
if (propertyPrefix == null) {
propertyPrefix = "";
}
try {
Project antProject = new Project();
File antBuildFile = this.writeTargetToProjectFile();
ProjectHelper.configureProject(antProject, antBuildFile);
antProject.init();
DefaultLogger antLogger = new MavenLogger(getLog());
if (getLog().isDebugEnabled()) {
antLogger.setMessageOutputLevel(Project.MSG_DEBUG);
} else if (getLog().isInfoEnabled()) {
antLogger.setMessageOutputLevel(Project.MSG_INFO);
} else if (getLog().isWarnEnabled()) {
antLogger.setMessageOutputLevel(Project.MSG_WARN);
} else if (getLog().isErrorEnabled()) {
antLogger.setMessageOutputLevel(Project.MSG_ERR);
} else {
antLogger.setMessageOutputLevel(Project.MSG_VERBOSE);
}
antProject.addBuildListener(antLogger);
antProject.setBaseDir(mavenProject.getBasedir());
Path p = new Path(antProject);
p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator));
/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
antProject.addReference(MAVEN_REFID_PREFIX + "dependency.classpath", p);
antProject.addReference(MAVEN_REFID_PREFIX + "compile.classpath", p);
p = new Path(antProject);
p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator));
antProject.addReference(MAVEN_REFID_PREFIX + "runtime.classpath", p);
p = new Path(antProject);
p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator));
antProject.addReference(MAVEN_REFID_PREFIX + "test.classpath", p);
/* set maven.plugin.classpath with plugin dependencies */
antProject.addReference(MAVEN_REFID_PREFIX + "plugin.classpath", getPathFromArtifacts(pluginArtifacts, antProject));
antProject.addReference(DEFAULT_MAVEN_PROJECT_REFID, mavenProject);
antProject.addReference(DEFAULT_MAVEN_PROJECT_REF_REFID, new MavenAntRunProject(mavenProject));
antProject.addReference(DEFAULT_MAVEN_PROJECT_HELPER_REFID, projectHelper);
antProject.addReference(MAVEN_REFID_PREFIX + "local.repository", localRepository);
initMavenTasks(antProject);
// The Ant project needs actual properties vs. using expression evaluator when calling an external build
// file.
copyProperties(mavenProject, antProject);
if (getLog().isInfoEnabled()) {
getLog().info("Executing tasks");
}
antProject.executeTarget(antTargetName);
if (getLog().isInfoEnabled()) {
getLog().info("Executed tasks");
}
copyProperties(antProject, mavenProject);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("DependencyResolutionRequiredException: " + e.getMessage(), e);
} catch (BuildException e) {
StringBuilder sb = new StringBuilder();
sb.append("An Ant BuildException has occured: ").append(e.getMessage());
String fragment = findFragment(e);
if (fragment != null) {
sb.append("\n").append(fragment);
}
if (!failOnError) {
getLog().info(sb.toString(), e);
// do not register roots.
return;
} else {
throw new MojoExecutionException(sb.toString(), e);
}
} catch (Throwable e) {
throw new MojoExecutionException("Error executing Ant tasks: " + e.getMessage(), e);
}
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AttachArtifactTask method execute.
/** {@inheritDoc} */
public void execute() {
if (file == null) {
throw new BuildException("File is a required parameter.");
}
if (!file.exists()) {
throw new BuildException("File does not exist: " + file);
}
if (this.getProject().getReference(mavenProjectRefId) == null) {
throw new BuildException("Maven project reference not found: " + mavenProjectRefId);
}
if (type == null) {
type = FileUtils.getExtension(file.getName());
}
MavenProject mavenProject = ((MavenAntRunProject) this.getProject().getReference(mavenProjectRefId)).getMavenProject();
if (this.getProject().getReference(mavenProjectHelperRefId) == null) {
throw new BuildException("Maven project helper reference not found: " + mavenProjectHelperRefId);
}
log("Attaching " + file + " as an attached artifact", Project.MSG_VERBOSE);
MavenProjectHelper projectHelper = (MavenProjectHelper) getProject().getReference(mavenProjectHelperRefId);
projectHelper.attachArtifact(mavenProject, type, classifier, file);
}
Aggregations