Example usage for org.apache.maven.project.artifact AttachedArtifact getFile

List of usage examples for org.apache.maven.project.artifact AttachedArtifact getFile

Introduction

In this page you can find the example usage for org.apache.maven.project.artifact AttachedArtifact getFile.

Prototype

public File getFile() 

Source Link

Usage

From source file:org.mule.devkit.maven.StudioPackageMojo.java

License:Open Source License

protected void createStudioPlugin(File studioPlugin) throws MojoExecutionException, ArchiverException {
    ModuleArchiver archiver = new ModuleArchiver();
    List attachedArtifacts = project.getAttachedArtifacts();

    AttachedArtifact mulePluginZipArtifact = null;
    for (Object object : attachedArtifacts) {
        AttachedArtifact attachedArtifact = (AttachedArtifact) object;
        if (attachedArtifact.getFile().getName().equals(finalName + ".zip")) {
            mulePluginZipArtifact = attachedArtifact;
        }/* w  ww. j  a va  2  s.c  o  m*/
    }

    if (mulePluginZipArtifact == null) {
        throw new MojoExecutionException("Mule Plugin zip file not available");
    }

    archiver.addFile(mulePluginZipArtifact.getFile(), mulePluginZipArtifact.getFile().getName());

    addArchivedClasses(archiver, File.separator);

    for (String fileName : MuleStudioPluginGenerator.GENERATED_FILES) {
        File file = new File(classesDirectory, fileName);
        if (!file.exists()) {
            throw new MojoExecutionException(
                    "Error while packagin Mule Studio plugin: " + file.getName() + " does not exist");
        }
        if (fileName.endsWith(".xml")) {
            replaceTokens(file);
        }
        archiver.addFile(file, file.getPath().substring(
                file.getPath().indexOf(classesDirectory.getPath()) + classesDirectory.getPath().length()));
    }

    archiver.addDirectory(new File(classesDirectory, MuleStudioIconsGenerator.ICONS_FOLDER),
            MuleStudioIconsGenerator.ICONS_FOLDER, null, null);

    archiver.setDestFile(studioPlugin);

    try {
        studioPlugin.delete();
        archiver.createArchive();
    } catch (IOException e) {
        throw new MojoExecutionException("Error while packaging Studio plugin", e);
    }
}