Example usage for org.apache.maven.plugin MojoExecutionException MojoExecutionException

List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException

Introduction

In this page you can find the example usage for org.apache.maven.plugin MojoExecutionException MojoExecutionException.

Prototype

public MojoExecutionException(String message, Throwable cause) 

Source Link

Document

Construct a new MojoExecutionException exception wrapping an underlying Throwable and providing a message.

Usage

From source file:com.actility.m2m.maven.plugin.apu.ApuMojo.java

License:Apache License

/**
 * Generates the APU.//  w  ww .  ja  v a2 s.  c  om
 */
public File createApu() throws MojoExecutionException {
    File apuFile = getApuFile(outputDirectory, finalName, classifier);

    ApuArchiver archiver = new ApuArchiver(apuFile, resourcesDirectory, classifier);

    apuConfig.setForced(false);
    apuConfig.setPackageName(packageName);
    apuConfig.setSource(source);
    apuConfig.setSection(section);
    apuConfig.setPriority(priority);
    apuConfig.setArchitecture(architecture);
    apuConfig.setEssential(essential);
    apuConfig.setMaintainer(maintainer);
    apuConfig.setDescription(description);
    apuConfig.setHomepage(homepage);

    try {
        File contentDirectory = resourcesDirectory;
        if (!contentDirectory.exists()) {
            getLog().warn("APU will be empty - no content was marked for inclusion!");
        }
        // Includes and excludes not supported for now...
        // else {
        // archiver.getArchiver().addDirectory(contentDirectory, getIncludes(), getExcludes());
        // }

        // File existingControl = defaultControlFile;

        // if (useDefaultControlFile && existingControl.exists() && apuConfig.getControlFile() == null) {
        // getLog().info("Adding existing control to archive. Found under: " + existingControl.getPath());
        // apuConfig.setControlFile(existingControl);
        // }

        archiver.createArchive(session, project, apuConfig);

        return apuFile;
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling APU", e);
    }
}

From source file:com.actility.maven.plugin.cocoon.AbstractDependencyFilterMojo.java

License:Apache License

/**
 * Method creates filters and filters the projects dependencies. This method also transforms the dependencies if classifier
 * is set. The dependencies are filtered in least specific to most specific order
 *
 * @param stopOnFailure/*from  ww w.j  a v a  2s. c o  m*/
 * @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
 * @throws MojoExecutionException
 */
protected DependencyStatusSets getDependencySets(boolean stopOnFailure) throws MojoExecutionException {
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();

    filter.addFilter(new ProjectTransitivityFilter(project.getDependencyArtifacts(), this.excludeTransitive));

    filter.addFilter(new ScopeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeScope),
            DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));

    filter.addFilter(new TypeFilter(DependencyUtil.cleanToBeTokenizedString(this.includeTypes),
            DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));

    filter.addFilter(new ClassifierFilter(DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers),
            DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));

    filter.addFilter(new GroupIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds),
            DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));

    filter.addFilter(new ArtifactIdFilter(DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds),
            DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));

    // start with all artifacts.
    @SuppressWarnings("unchecked")
    Set<Artifact> artifacts = project.getArtifacts();

    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    // transform artifacts if classifier is set
    DependencyStatusSets status = null;
    if (StringUtils.isNotEmpty(classifier)) {
        status = getClassifierTranslatedDependencies(artifacts, stopOnFailure);
    } else {
        status = filterMarkedDependencies(artifacts);
    }

    return status;
}

From source file:com.actility.maven.plugin.cocoon.AbstractDependencyFilterMojo.java

License:Apache License

/**
 * Filter the marked dependencies/*from  w w w. j  ava 2  s.c o m*/
 *
 * @param artifacts
 * @return
 * @throws MojoExecutionException
 */
protected DependencyStatusSets filterMarkedDependencies(Set<Artifact> artifacts) throws MojoExecutionException {
    // remove files that have markers already
    FilterArtifacts filter = new FilterArtifacts();
    filter.clearFilters();
    filter.addFilter(getMarkedArtifactFilter());

    Set<Artifact> unMarkedArtifacts;
    try {
        unMarkedArtifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

    // calculate the skipped artifacts
    Set<Artifact> skippedArtifacts = new HashSet<Artifact>();
    skippedArtifacts.addAll(artifacts);
    skippedArtifacts.removeAll(unMarkedArtifacts);

    return new DependencyStatusSets(unMarkedArtifacts, null, skippedArtifacts);
}

From source file:com.actility.maven.plugin.cocoon.DefaultArtifactsResolver.java

License:Apache License

public Set<Artifact> resolve(Set<Artifact> artifacts, Log log) throws MojoExecutionException {

    Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
    for (Artifact artifact : artifacts) {
        try {/* w  w  w.  j  a  v  a2  s. co  m*/
            resolver.resolve(artifact, remoteRepositories, local);
            resolvedArtifacts.add(artifact);
        } catch (ArtifactResolutionException ex) {
            // an error occurred during resolution, log it an continue
            log.debug("error resolving: " + artifact.getId());
            log.debug(ex);
            if (stopOnFailure) {
                throw new MojoExecutionException("error resolving: " + artifact.getId(), ex);
            }
        } catch (ArtifactNotFoundException ex) {
            // not found, log it and continue
            log.debug("not found in any repository: " + artifact.getId());
            if (stopOnFailure) {
                throw new MojoExecutionException("not found in any repository: " + artifact.getId(), ex);
            }
        }
    }
    return resolvedArtifacts;
}

From source file:com.actility.maven.plugin.cocoon.GenerateKfCocoonMojo.java

License:Apache License

private void buildInitXargs(Map<Integer, LevelConfiguration> levelsConfiguration)
        throws MojoExecutionException {
    File initXargsFile = new File(kfBaseDirectory, "init.xargs");
    BufferedWriter out = null;//from w  ww  .j  a va2 s . c  o  m
    try {
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(initXargsFile), "ASCII"));

        // Headers
        out.write("#\n");
        out.write("# Generated cocoon init file\n");
        out.write("#\n");
        out.write("\n");
        out.write("# load common properties\n");
        out.write("-xargs props.xargs\n");
        out.write("\n");
        out.write("# Semicolon seprated list of base URLs for searching (completing)\n");
        out.write("# bundle URLs in \"-install URL\" command line options and in the console.\n");
        out.write("-Dorg.knopflerfish.gosg.jars=file:");
        out.write(getRelativePath(factoryDirectory, kfBaseDirectory));
        out.write("\n");
        out.write("\n");
        out.write("-init\n");
        out.write("\n");

        // Body
        for (LevelConfiguration levelConfig : levelsConfiguration.values()) {
            if (levelConfig.getDescription() != null) {
                out.write("# ");
                out.write(levelConfig.getDescription());
                out.write("\n");
            }
            out.write("-initlevel ");
            out.write(String.valueOf(levelConfig.getLevel()));
            out.write("\n");

            for (BundleConfiguration bundleConfig : levelConfig.getBundlesConfiguration()) {
                if (bundleConfig.isComment()) {
                    out.write("#");
                }
                out.write("-install ");
                out.write(bundleConfig.getDestFile());
                out.write("\n");
            }
            out.write("\n");
        }
        out.write("\n");

        out.write("-startlevel ");
        out.write(String.valueOf(initialStartLevel));
        out.write("\n");
        out.write("\n");
        out.write("\n");

        out.write("# Start of these bundles are delayed since this makes start\n");
        out.write("# order dependencies much easier\n");
        out.write("\n");

        for (LevelConfiguration levelConfig : levelsConfiguration.values()) {
            for (BundleConfiguration bundleConfig : levelConfig.getBundlesConfiguration()) {
                if (bundleConfig.isComment()) {
                    out.write("#");
                }
                out.write("-start ");
                out.write(bundleConfig.getDestFile());
                out.write("\n");
            }
            out.write("\n");
        }
    } catch (IOException e) {
        throw new MojoExecutionException("IO problem while generating init.xargs file", e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            throw new MojoExecutionException("IO problem while closing init.xargs file", e);
        }
    }
}

From source file:com.actility.maven.plugin.cocoon.GenerateKfCocoonMojo.java

License:Apache License

private void buildFirmwareManifest(List<FirmwareEntryConfiguration> firmwareEntries, File destDir,
        String firmwareQualifier) throws MojoExecutionException {
    File firmwareManifestFile = new File(destDir, "firmware-manifest.properties");
    BufferedWriter out = null;//from   w w  w  . j  a va 2 s  .  com
    int index = 0;
    try {

        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(firmwareManifestFile), "ASCII"));

        out.write("firmware.versionPrefix=");
        out.write(versionPrefix);
        out.write("\n");
        out.write("firmware.versionNumber=");
        Artifact artifact = project.getArtifact();
        out.write(MavenUtils.getOSGiVersion(artifact));
        // Add firmware extra qualifier to firmware.versionNumber
        if (firmwareQualifier != null) {
            if (StringUtils.isNotEmpty(artifact.getSelectedVersion().getQualifier())) {
                out.write("_");
            } else {
                out.write(".");
            }
            out.write(firmwareQualifier);
        }

        out.write("\n");
        out.write("\n");

        // part.{index}.id=
        // part.{index}.namespace=
        // part.{index}.name=
        // part.{index}.version=
        // part.{index}.fullname=
        // part.{index}.installationType=
        for (FirmwareEntryConfiguration firmwareEntry : firmwareEntries) {
            if (!firmwareEntry.isOneTime()) {
                ++index;
                String prefix = "";
                if (firmwareEntry.isComment()) {
                    prefix += "#";
                }
                prefix += "part." + String.valueOf(index) + ".";

                out.write(prefix + "id=");
                out.write(firmwareEntry.getId());
                out.write("\n");
                out.write(prefix + "namespace=");
                out.write(firmwareEntry.getNamespace());
                out.write("\n");
                out.write(prefix + "name=");
                out.write(firmwareEntry.getName());
                out.write("\n");
                out.write(prefix + "version=");
                out.write(firmwareEntry.getVersion());
                out.write("\n");
                out.write(prefix + "fullname=");
                out.write(firmwareEntry.getDestFile());
                out.write("\n");
                out.write(prefix + "installationType=");
                out.write(firmwareEntry.getInstallationType());
                out.write("\n");
                out.write("\n");
            }
        }
        out.write("\n");
    } catch (IOException e) {
        throw new MojoExecutionException("IO problem while generating firmware-manifest.properties file", e);
    } catch (OverConstrainedVersionException e) {
        throw new MojoExecutionException("Failed to retrieve project artifact version", e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            throw new MojoExecutionException("IO problem while closing firmware-manifest.properties file", e);
        }
    }
}

From source file:com.actility.maven.plugin.cocoon.GenerateKfCocoonMojo.java

License:Apache License

private void copyFile(File artifact, File destFile) throws MojoExecutionException {
    try {/*  ww  w  .  j a  va  2 s .co  m*/
        getLog().info("Copying " + artifact.getAbsolutePath() + " to " + destFile);
        FileUtils.copyFile(artifact, destFile);
    } catch (Exception e) {
        throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e);
    }
}

From source file:com.actility.maven.plugin.cocoon.GenerateKfCocoonMojo.java

License:Apache License

private void buildFirmwareFile(List<FirmwareEntryConfiguration> firmwareEntries, File destDir,
        String firmwareQualifier) throws MojoExecutionException {
    StringBuffer destFileName = new StringBuffer();

    try {/* ww  w  . j  ava 2  s . com*/
        destFileName.append(project.getArtifactId()).append("-").append(project.getVersion());
        if (firmwareQualifier != null) {
            if (StringUtils.isNotEmpty(project.getArtifact().getSelectedVersion().getQualifier())) {
                destFileName.append("_").append(firmwareQualifier);
            } else {
                destFileName.append("-").append(firmwareQualifier);
            }
        }
        destFileName.append("-firmware.zip");
        File destFile = new File(buildDirectory, destFileName.toString());
        Archiver archiver = archiverManager.getArchiver(destFile);
        archiver.setDestFile(destFile);

        List<String> excludes = new ArrayList<String>();
        excludes.add("cfg/");
        for (FirmwareEntryConfiguration firmwareEntry : firmwareEntries) {
            if (firmwareEntry.isOneTime()) {
                excludes.add(firmwareEntry.getDestFile());
            }
        }

        DefaultFileSet fileSet = new DefaultFileSet();
        fileSet.setDirectory(destDir);
        fileSet.setPrefix("");
        fileSet.setIncludes(null);
        fileSet.setExcludes(excludes.toArray(new String[excludes.size()]));
        fileSet.setIncludingEmptyDirectories(true);
        archiver.addFileSet(fileSet);

        archiver.createArchive();
    } catch (OverConstrainedVersionException e) {
        throw new MojoExecutionException("Cannot build firmware file", e);
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Cannot build firmware file", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Cannot build firmware file", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot build firmware file", e);
    }
}

From source file:com.actility.maven.plugin.cocoon.GenerateKfInitMojo.java

License:Apache License

private void buildInitXargs(Map<Integer, LevelConfiguration> levelsConfiguration)
        throws MojoExecutionException {
    File initXargsFile = new File(kfConfigDirectory, "init.xargs");
    BufferedWriter out = null;//from  w  ww.j a v a2 s  . c o  m
    try {
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(initXargsFile), "ASCII"));

        // Headers
        out.write("#\n");
        out.write("# Generated cocoon init file\n");
        out.write("#\n");
        out.write("\n");
        out.write("# load common properties\n");
        out.write("-xargs props.xargs\n");
        out.write("\n");
        out.write("# Semicolon seprated list of base URLs for searching (completing)\n");
        out.write("# bundle URLs in \"-install URL\" command line options and in the console.\n");
        out.write("-Dorg.knopflerfish.gosg.jars=file:../../../lib/osgi/\n");
        out.write("\n");
        out.write("-init\n");
        out.write("\n");

        // Body
        for (LevelConfiguration levelConfig : levelsConfiguration.values()) {
            if (levelConfig.getDescription() != null) {
                String[] descriptions = levelConfig.getDescription().split("\n");
                for (String description : descriptions) {
                    out.write("# ");
                    out.write(description);
                    out.write("\n");
                }
            }
            out.write("-initlevel ");
            out.write(String.valueOf(levelConfig.getLevel()));
            out.write("\n");

            for (BundleConfiguration bundleConfig : levelConfig.getBundlesConfiguration()) {
                if (bundleConfig.isComment()) {
                    out.write("#");
                }
                out.write("-install ");
                out.write(bundleConfig.getDestFile());
                out.write("\n");
            }
            out.write("\n");
        }
        out.write("\n");

        out.write("-startlevel ");
        out.write(String.valueOf(initialStartLevel));
        out.write("\n");
        out.write("\n");
        out.write("\n");

        out.write("# Start of these bundles are delayed since this makes start\n");
        out.write("# order dependencies much easier\n");
        out.write("\n");

        for (LevelConfiguration levelConfig : levelsConfiguration.values()) {
            for (BundleConfiguration bundleConfig : levelConfig.getBundlesConfiguration()) {
                if (bundleConfig.toStart()) {
                    if (bundleConfig.isComment()) {
                        out.write("#");
                    }
                    out.write("-start ");
                    out.write(bundleConfig.getDestFile());
                    out.write("\n");
                }
            }
            out.write("\n");
        }
    } catch (IOException e) {
        throw new MojoExecutionException("IO problem while generating init.xargs file", e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            throw new MojoExecutionException("IO problem while closing init.xargs file", e);
        }
    }
}

From source file:com.adaptiweb.mojo.BuildNumberMojo.java

License:Apache License

private SVNInfo getSVNInfo() throws MojoExecutionException {
    if (svnInfo == null)
        try {//from   w w  w  .  j  a  v  a  2s.c om
            svnInfo = getSVNManager().getWCClient().doInfo(basedir, SVNRevision.BASE);
        } catch (SVNException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    return svnInfo;
}