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

org.jvnet.maven.plugin.antrun.PackagingCondition 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.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.condition.Condition;

/**
 * @author Kohsuke Kawaguchi
 * @author Paul Sterk
 */
public class PackagingCondition implements Condition{
    
    private String is = "";
    
    public void setIs(String is) {
        this.is = is;
    }
    
    public boolean eval() throws BuildException {
        Artifact artifact = ResolveAllTask.CURRENT_ARTIFACT.get();
        // Get the pom.xml file for each artifact
        MavenComponentBag w = MavenComponentBag.get();
        try {
            // TODO: reuse the laoded project among ohter conditions
            MavenProject p = w.mavenProjectBuilder.buildFromRepository(artifact, 
                                                                       w.project.getRemoteArtifactRepositories(), 
                                                                       w.localRepository);

            String packagingValue = p.getPackaging();
            if (packagingValue == null) {
                // Set to default Maven packaging type
                // TODO. Use a maven constant to set this value. Remove hard wiring value.
                packagingValue = "jar";
            }
            return is.matches(packagingValue);
        } catch (ProjectBuildingException e) {
            throw new BuildException("Failed to load POM for "+artifact,e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy