Artifact.java

package org.docascode.ant.types;

import org.apache.commons.io.FilenameUtils;
import org.apache.tools.ant.types.DataType;
import org.docascode.api.core.Substitute;
import org.docascode.api.core.errors.DocAsCodeException;
import org.docascode.api.core.office.Properties;
import org.eclipse.aether.artifact.DefaultArtifact;

import java.io.File;
import java.util.Map;

public class Artifact extends DataType {
    private String groupId;
    public void setGroupId(String groupId){
        this.groupId = groupId;
    }

    private String artifactId;
    public void setArtifactId(String artifactId){
        this.artifactId = artifactId;
    }

    private String version;
    public void setVersion(String version){
        this.version = version;
    }

    private String classifier;
    public void setClassifier(String classifier){
        this.classifier = classifier;
    }

    private String extension;
    public void setExtension(String extension){
        this.extension = extension;
    }

    private File file;
    public void setFile (File file){
        this.file = file;
    }

    public org.eclipse.aether.artifact.Artifact toArtifact() throws DocAsCodeException {
        if (file != null){
            this.extension = FilenameUtils.getExtension(file.getAbsolutePath());
        }
        Map<String,String> dict = Properties.list(file);
        org.eclipse.aether.artifact.Artifact result =
                new DefaultArtifact(Substitute.substitute(groupId,dict),
                        Substitute.substitute(artifactId,dict),
                        Substitute.substitute(classifier,dict),
                        extension,
                        Substitute.substitute(version,dict));
        result = result.setFile(file);
        return result;
    }
}