All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.maven.plugin.antrun.ResolveProjectArtifactIdTask Maven / Gradle / Ivy

Go to download

This extended antrun maven plugin enables users not only to run ant scripts embedded in the POM, but also to reference maven dependencies using Ant task classes. This enables the user to delegate more complex tasks to Ant such as constructing file-based installation distros.

There is a newer version: 1.43
Show newest version
package org.jvnet.maven.plugin.antrun;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;

/**
 * This class Ant Task is used to obtain the name of the fully qualified
 * Maven artifactId (-. ) from the local
 * project pom.xml file.
 * 
 * @author psterk
 */
public class ResolveProjectArtifactIdTask extends Task {
    
    // Avoid NPEs by setting a default value
    private String property = "artifactId";
    
    public void setProperty(String property) {
        this.property = property;
    }
    
    public void execute() throws BuildException {
        log("Project artifactId property name: "+property, Project.MSG_VERBOSE);
        final MavenComponentBag w = MavenComponentBag.get();
        String artifactId = w.project.getArtifactId();
        String version = w.project.getVersion();
        String packaging = w.project.getPackaging();
        String fileExtension = "";
        if (packaging.equalsIgnoreCase("distribution-base-zip") ||
            packaging.equalsIgnoreCase("glassfish-distribution")) {
            fileExtension = "zip";
        } else {
            fileExtension = packaging;
        }
        StringBuffer sb = new StringBuffer(artifactId);
        sb.append("-").append(version).append(".").append(fileExtension);
        log("Project artifactId: "+sb.toString(), Project.MSG_VERBOSE);
        getProject().setProperty(property, sb.toString());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy