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) 

Source Link

Document

Construct a new MojoExecutionException exception providing a message.

Usage

From source file:cn.org.once.cstack.maven.plugin.utils.RestUtils.java

License:Open Source License

/**
 * @param url// ww w .j  a  v  a2  s  . c  om
 * @param parameters
 * @param log
 * @return
 * @throws MojoExecutionException
 */
public Map<String, String> connect(String url, Map<String, Object> parameters, Log log)
        throws MojoExecutionException {

    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    List<NameValuePair> nvps = new ArrayList<>();
    nvps.add(new BasicNameValuePair("j_username", (String) parameters.get("login")));
    nvps.add(new BasicNameValuePair("j_password", (String) parameters.get("password")));
    localContext = HttpClientContext.create();
    localContext.setCookieStore(new BasicCookieStore());
    HttpPost httpPost = new HttpPost(url);

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
        CloseableHttpResponse httpResponse = httpclient.execute(httpPost, localContext);
        ResponseHandler<String> handler = new ResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put("body", body);
        httpResponse.close();
        isConnected = true;
        log.info("Connection successful");
    } catch (Exception e) {
        log.error("Connection failed!  : " + e.getMessage());
        isConnected = false;
        throw new MojoExecutionException(
                "Connection failed, please check your manager location or your credentials");
    }

    return response;
}

From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.WarProjectPackagingTask.java

License:Apache License

/**
 * Handles the web resources./*from  w  w  w .  j a va2s  .  co  m*/
 *
 * @param context the packaging context
 * @throws MojoExecutionException if a resource could not be copied
 */
protected void handleWebResources(WarPackagingContext context) throws MojoExecutionException {
    for (Resource resource : webResources) {

        // MWAR-246
        if (resource.getDirectory() == null) {
            throw new MojoExecutionException("The <directory> tag is missing from the <resource> tag.");
        }

        if (!(new File(resource.getDirectory())).isAbsolute()) {
            resource.setDirectory(context.getProject().getBasedir() + File.separator + resource.getDirectory());
        }

        // Make sure that the resource directory is not the same as the webappDirectory
        if (!resource.getDirectory().equals(context.getWebappDirectory().getPath())) {

            try {
                copyResources(context, resource);
            } catch (IOException e) {
                throw new MojoExecutionException("Could not copy resource [" + resource.getDirectory() + "]",
                        e);
            }
        }
    }
}

From source file:codes.writeonce.maven.plugins.soy.ExtractMessagesMojo.java

License:Open Source License

@Override
protected void process() throws Exception {

    super.process();

    if (outputFile == null) {
        outputFile = new File(DEFAULT_XLIFF_OUTPUT_PATH + targetLocale + XLIFF_EXTENSION);
    }//from   ww w .  j a  v a2  s.  c o m

    outputFile = getSafePath(outputFile);

    if (Files.exists(outputFile.toPath())) {
        if (overwrite) {
            getLog().info("Overwriting the existing file: " + outputFile);
        } else {
            getLog().error("File already exists: " + outputFile);
            throw new MojoExecutionException("File already exists: " + outputFile);
        }
    } else {
        getLog().info("Generating the messages file: " + outputFile);
    }

    final SoyMsgBundleHandler.OutputFileOptions options = new SoyMsgBundleHandler.OutputFileOptions();
    options.setSourceLocaleString(sourceLocale);

    if (targetLocale.length() > 0) {
        options.setTargetLocaleString(targetLocale);
    }

    final SoyMsgBundleHandler msgBundleHandler = new SoyMsgBundleHandler(new XliffMsgPlugin());
    final SoyMsgBundle soyMsgBundle = getSoyFileSet(getSoyFiles()).extractMsgs();
    msgBundleHandler.writeToExtractedMsgsFile(soyMsgBundle, options, outputFile);
}

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

License:Apache License

public void execute() throws MojoExecutionException {
    if (!resourcesDirectory.exists()) {
        throw new MojoExecutionException(
                "Cannot create the apu, no resources found in " + resourcesDirectory.getAbsolutePath());
    }// w  w w .j a  va 2 s.  com
    if (description == null && project.getDescription() == null) {
        throw new MojoExecutionException("No description provided for APU");
    }
    getLog().info("Classifier: " + classifier);
    getLog().info("Architecture: " + architecture);
    File apuFile = createApu();

    if (classifier != null) {
        projectHelper.attachArtifact(project, "apu", classifier, apuFile);
    } else {
        project.getArtifact().setFile(apuFile);
    }
}

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

License:Apache License

/**
 * Does the actual copy of the file and logging.
 *
 * @param artifact represents the file to copy.
 * @param destFile file name of destination file.
 * @throws MojoExecutionException with a message if an error occurs.
 *//*from w  w w. ja  v  a 2s.  co  m*/
protected void copyFile(File artifact, File destFile) throws MojoExecutionException {
    Log theLog = this.getLog();
    try {
        theLog.info("Copying "
                + (this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName())
                + " to " + destFile);

        if (artifact.isDirectory()) {
            // usual case is a future jar packaging, but there are special cases: classifier and other packaging
            throw new MojoExecutionException(
                    "Artifact has not been packaged yet. When used on reactor artifact, "
                            + "copy should be executed after packaging: see MDEP-187.");
        }

        FileUtils.copyFile(artifact, destFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e);
    }
}

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

License:Apache License

/**
 * Unpacks the archive file./*from w ww  .  ja  v a  2s .  c om*/
 *
 * @param file File to be unpacked.
 * @param location Location where to put the unpacked files.
 * @param includes Comma separated list of file patterns to include i.e. <code>**&#47;.xml,
 *                 **&#47;*.properties</code>
 * @param excludes Comma separated list of file patterns to exclude i.e. <code>**&#47;*.xml,
 *                 **&#47;*.properties</code>
 */
protected void unpack(File file, File location, String includes, String excludes)
        throws MojoExecutionException {
    try {
        logUnpack(file, location, includes, excludes);

        location.mkdirs();

        if (file.isDirectory()) {
            // usual case is a future jar packaging, but there are special cases: classifier and other packaging
            throw new MojoExecutionException(
                    "Artifact has not been packaged yet. When used on reactor artifact, "
                            + "unpack should be executed after packaging: see MDEP-98.");
        }

        UnArchiver unArchiver;

        unArchiver = archiverManager.getUnArchiver(file);

        unArchiver.setUseJvmChmod(useJvmChmod);

        unArchiver.setSourceFile(file);

        unArchiver.setDestDirectory(location);

        if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
            // Create the selectors that will filter
            // based on include/exclude parameters
            // MDEP-47
            IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] {
                    new IncludeExcludeFileSelector() };

            if (StringUtils.isNotEmpty(excludes)) {
                selectors[0].setExcludes(excludes.split(","));
            }

            if (StringUtils.isNotEmpty(includes)) {
                selectors[0].setIncludes(includes.split(","));
            }

            unArchiver.setFileSelectors(selectors);
        }
        if (this.silent) {
            silenceUnarchiver(unArchiver);
        }

        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unknown archiver type", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException(
                "Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
    }
}

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

public BundleConfiguration(Log log, Map<String, Artifact> nameTodependency, String classifier, String[] args)
        throws MojoExecutionException {
    super(log);//w w w.j a v a  2 s.  c  o  m
    if (args.length < 3 || args.length > 7) {
        throw new MojoExecutionException(
                "Bundle configuration has a wrong number of arguments: " + StringUtils.join(args, ":"));
    }
    try {
        artifact = nameTodependency.get(args[0] + ":" + args[1]);
        if (artifact == null) {
            artifact = nameTodependency.get(args[0] + ":" + args[1] + ":" + classifier);
            if (artifact == null) {
                throw new MojoExecutionException("Bundle dependency does not exist: " + args[0] + ":" + args[1]
                        + ((classifier != null) ? ":" + classifier : ""));
            }
        }
        startLevel = Integer.parseInt(args[2]);
        if (startLevel < 1) {
            throw new MojoExecutionException(
                    "Bundle configuration start level is stricly lower than 1: " + StringUtils.join(args, ":"));
        }
        if (args.length >= 4) {
            toStart = Boolean.parseBoolean(args[3]);
        } else {
            toStart = true;
        }
        if (args.length >= 5) {
            comment = Boolean.parseBoolean(args[4]);
        } else {
            comment = false;
        }
        boolean deploymentPlugin = false;
        if (args.length >= 6) {
            deploymentPlugin = Boolean.parseBoolean(args[5]);
        }
        if (args.length >= 7) {
            oneTime = Boolean.parseBoolean(args[6]);
        } else {
            oneTime = false;
        }
        // Load manifest read values and check content
        JarInputStream jarStream = new JarInputStream(new FileInputStream(artifact.getFile()));
        Attributes attributes = jarStream.getManifest().getMainAttributes();
        checkManifest(attributes);

        id = attributes.getValue("Bundle-SymbolicName");
        int semicolonIndex = id.indexOf(';');
        if (semicolonIndex != -1) {
            id = id.substring(0, semicolonIndex);
        }
        namespace = "osgiBundleSymbolicName";
        name = attributes.getValue("Bundle-Name");
        if (deploymentPlugin) {
            installationType = "deploymentPluginBundle";
        } else {
            installationType = "osgiBundle";
        }
        version = attributes.getValue("Bundle-Version");
    } catch (NumberFormatException e) {
        throw new MojoExecutionException(
                "Bundle configuration start level is not a number: " + StringUtils.join(args, ":"), e);
    } catch (IOException e) {
        throw new MojoExecutionException(
                "A problem occured while reading jar from dependency: " + StringUtils.join(args, ":"), e);
    }
}

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

private void checkManifest(Attributes attributes) throws MojoExecutionException {
    String bundleManifest = attributes.getValue("Bundle-ManifestVersion");
    String bundleSymbolicName = attributes.getValue("Bundle-SymbolicName");
    String bundleVersion = attributes.getValue("Bundle-Version");

    String bundleName = attributes.getValue("Bundle-Name");
    String bundleLicense = attributes.getValue("Bundle-License");
    String bundleVendor = attributes.getValue("Bundle-Vendor");

    String exportPackage = attributes.getValue("Export-Package");
    String importPackage = attributes.getValue("Import-Package");
    if (bundleManifest == null) {
        throw new MojoExecutionException("Bundle manifest does not have Bundle-ManifestVersion ("
                + artifact.getGroupId() + ":" + artifact.getArtifactId() + ")");
    } else if (!"2".equals(bundleManifest)) {
        throw new MojoExecutionException("Bundle manifest does not have Bundle-ManifestVersion equals to 2 ("
                + artifact.getGroupId() + ":" + artifact.getArtifactId() + "): " + bundleManifest);
    }//from w  w w.j a  va2 s. c om
    if (bundleSymbolicName == null) {
        throw new MojoExecutionException("Bundle manifest does not have Bundle-SymbolicName ("
                + artifact.getGroupId() + ":" + artifact.getArtifactId() + ")");
    }
    if (bundleVersion == null) {
        throw new MojoExecutionException("Bundle manifest does not have Bundle-Version(" + artifact.getGroupId()
                + ":" + artifact.getArtifactId() + ")");
    }

    if (bundleName == null) {
        log.warn("Bundle manifest does not have Bundle-Name (" + artifact.getGroupId() + ":"
                + artifact.getArtifactId() + ")");
    }
    if (bundleLicense == null) {
        log.warn("Bundle manifest does not have Bundle-License (" + artifact.getGroupId() + ":"
                + artifact.getArtifactId() + ")");
    }
    if (bundleVendor == null) {
        log.warn("Bundle manifest does not have Bundle-Vendor (" + artifact.getGroupId() + ":"
                + artifact.getArtifactId() + ")");
    }

    if (exportPackage != null) {
        List<String> exportPackageDecls = buildPackageList(exportPackage);
        for (String exportPackageDecl : exportPackageDecls) {
            log.debug("Check export-package: " + exportPackageDecl);
            if (!exportPackageDecl.matches(".*;[ ]*version[ ]*=.*")
                    && !exportPackageDecl.matches(".*;[ ]*specification-version[ ]*=.*")) {
                log.warn("Bundle Export-Package declaration does not have version (" + artifact.getGroupId()
                        + ":" + artifact.getArtifactId() + "): " + exportPackageDecl);
            }
        }
    }
    if (importPackage != null) {
        List<String> importPackageDecls = buildPackageList(importPackage);
        for (String importPackageDecl : importPackageDecls) {
            log.debug("Check import-package: " + importPackageDecl);
            if (!importPackageDecl.matches(".*;[ ]*version[ ]*=.*")
                    && !importPackageDecl.matches(".*;[ ]*specification-version[ ]*=.*")) {
                log.warn("Bundle Import-Package declaration does not have version (" + artifact.getGroupId()
                        + ":" + artifact.getArtifactId() + "): " + importPackageDecl);
            }
        }
    }
}

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

License:Apache License

private void buildRootAct() throws MojoExecutionException {
    try {/*w w  w.j a v a 2s  . c  o  m*/
        Map<String, String> modulesMapping = buildModulesMapping();
        DependencyStatusSets dss = getDependencySets(true);
        Set<Artifact> dependencies = dss.getResolvedDependencies();

        Set<Artifact> skippedArtifacts = dss.getSkippedDependencies();
        for (Artifact artifact : skippedArtifacts) {
            getLog().info(artifact.getFile().getName() + " already exists in destination.");
        }

        List<String> excludedArchitecturesList = (excludeArchitectures != null)
                ? Arrays.asList(excludeArchitectures.split(","))
                : Collections.EMPTY_LIST;
        List<String> excludedProductsList = (excludeProducts != null)
                ? Arrays.asList(excludeProducts.split(","))
                : Collections.EMPTY_LIST;
        List<String> excludedModulesList = (excludeModules != null) ? Arrays.asList(excludeModules.split(","))
                : Collections.EMPTY_LIST;
        File tmpDir = new File(buildDirectory, "tmp");
        tmpDir.mkdir();
        File destDir = null;
        for (Artifact artifact : dependencies) {

            if ("jar".equals(artifact.getType())) {
                if (isBundle(artifact)) {
                    if (artifact.getClassifier() != null) {
                        destDir = new File(
                                outputDirectory.getAbsolutePath() + "/arch/" + artifact.getClassifier() + "/"
                                        + getModule(modulesMapping, artifact) + "/data/lib/osgi/");
                    } else {
                        destDir = new File(outputDirectory.getAbsolutePath() + "/common/"
                                + getModule(modulesMapping, artifact) + "/data/lib/osgi/");
                    }
                } else {
                    if (artifact.getClassifier() != null) {
                        destDir = new File(
                                outputDirectory.getAbsolutePath() + "/arch/" + artifact.getClassifier() + "/"
                                        + getModule(modulesMapping, artifact) + "/data/lib/java/");
                    } else {
                        destDir = new File(outputDirectory.getAbsolutePath() + "/common/"
                                + getModule(modulesMapping, artifact) + "/data/lib/java/");
                    }
                }
                destDir.mkdirs();
                copyFile(artifact.getFile(), new File(destDir, artifact.getFile().getName()));
            } else if ("apu".equals(artifact.getType())) {
                removeDirectoryContent(tmpDir);

                if (artifact.getClassifier() != null) {
                    destDir = new File(outputDirectory.getAbsolutePath() + "/arch/" + artifact.getClassifier()
                            + "/" + getModule(modulesMapping, artifact) + "/");
                } else {
                    destDir = new File(outputDirectory.getAbsolutePath() + "/common/"
                            + getModule(modulesMapping, artifact) + "/");
                }

                // Untar file in tmp directory
                tarGzipArchiver.setSourceFile(artifact.getFile());
                tarGzipArchiver.setDestDirectory(tmpDir);
                tarGzipArchiver.extract();

                // Control
                tarGzipArchiver.setSourceFile(new File(tmpDir, "control.tar.gz"));
                tarGzipArchiver.setDestDirectory(tmpDir);
                tarGzipArchiver.extract();

                File preInstall = new File(tmpDir.getAbsolutePath() + "/preinst");
                File postInstall = new File(tmpDir.getAbsolutePath() + "/postinst");

                if (preInstall.exists()) {
                    copyFile(preInstall, new File(
                            destDir.getAbsolutePath() + "/control/preinst/" + artifact.getArtifactId()));
                }
                if (postInstall.exists()) {
                    copyFile(postInstall, new File(
                            destDir.getAbsolutePath() + "/control/postinst/" + artifact.getArtifactId()));
                }

                // Control
                destDir = new File(destDir, "data");
                destDir.mkdirs();
                tarGzipArchiver.setSourceFile(new File(tmpDir, "data.tar.gz"));
                tarGzipArchiver.setDestDirectory(destDir);
                tarGzipArchiver.extract();
            } else {
                throw new MojoExecutionException("Unknown artifact type (" + artifact.getType()
                        + ") for dependency (" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
                        + artifact.getVersion() + ")");
            }
        }
        for (String arch : excludedArchitecturesList) {
            arch = arch.trim();
            if (arch.length() > 1) {
                removeDirectory(new File(outputDirectory.getAbsolutePath() + "/arch/" + arch + "/"));
            }
        }
        for (String product : excludedProductsList) {
            product = product.trim();
            if (product.length() > 1) {
                removeDirectory(new File(outputDirectory.getAbsolutePath() + "/product/" + product + "/"));
            }
        }
        for (String module : excludedModulesList) {
            module = module.trim();
            if (module.length() > 1) {
                removeDirectory(new File(outputDirectory.getAbsolutePath() + "/module/" + module + "/"));
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("IOException: ", e);
    }
}

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

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    try {/*from   ww  w. j a  va 2s .  c o  m*/
        if (!kfBaseDirectory.isDirectory()) {
            throw new MojoExecutionException("KF base directory does not exist: " + kfBaseDirectory);
        }
        if (!factoryDirectory.isDirectory()) {
            throw new MojoExecutionException("Factory directory does not eists: " + factoryDirectory);
        }
        getLog().debug("Read bundlesConfiguration: " + bundlesConfiguration);
        getLog().debug("Read kfBaseDirectory: " + kfBaseDirectory);
        getLog().debug("Read factoryDirectory: " + factoryDirectory);

        Set<Artifact> dependencies = project.getDependencyArtifacts();
        nameToDependency = new HashMap<String, Artifact>();
        for (Artifact artifact : dependencies) {
            nameToDependency.put(artifact.getGroupId() + "~" + artifact.getArtifactId(), artifact);
        }

        nameVersionToDependency = new HashMap<String, Artifact>();
        for (Artifact artifact : dependencies) {
            nameVersionToDependency.put(
                    artifact.getGroupId() + "~" + artifact.getArtifactId() + "~" + artifact.getVersion(),
                    artifact);
        }

        // Build levels configuration
        Map<Integer, LevelConfiguration> levelsConfigurations = buildLevelsConfiguration();
        // Build bundles configuration
        buildBundlesConfiguration(levelsConfigurations);
        // Build firmware entries configuration
        List<FirmwareEntryConfiguration> firmwareEntries = buildFirmwareEntriesConfiguration(
                levelsConfigurations);
        // Build init.xargs
        buildInitXargs(levelsConfigurations);
        // Build firmware-manifest.properties
        buildFirmwareManifest(firmwareEntries, factoryDirectory, firmwareQualifier);
        // Copy cocoon bundles
        copyFirmwareEntries(firmwareEntries, factoryDirectory);
        // Build firmware file
        buildFirmwareFile(firmwareEntries, factoryDirectory, firmwareQualifier);
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}