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

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

Introduction

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

Prototype

public MojoFailureException(String message) 

Source Link

Document

Construct a new MojoFailureException exception providing a message.

Usage

From source file:apparat.embedding.maven.AbstractApparatMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  ww.j  a v  a 2  s  .co m*/
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final MavenLogAdapter logAdapter = new MavenLogAdapter(getLog());

    try {
        apparat.log.Log.setLevel(logAdapter.getLevel());
        apparat.log.Log.addOutput(logAdapter);

        if (null == overrideArtifact) {
            if (null != project) {
                processArtifact(project.getArtifact());

                for (final Artifact artifact : project.getAttachedArtifacts()) {
                    processArtifact(artifact);
                }
            }
        } else {
            if (!overrideArtifact.exists()) {
                if (failIfOverrideIsMissing) {
                    throw new MojoFailureException("File " + overrideArtifact + " does not exist.");
                } else {
                    getLog().warn("Override " + overrideArtifact + " is missing.");
                    return;
                }
            }

            try {
                processFile(overrideArtifact);
            } catch (final Throwable cause) {
                throw new MojoExecutionException("Apparat execution failed.", cause);
            }
        }
    } finally {
        apparat.log.Log.removeOutput(logAdapter);
    }
}

From source file:apparat.embedding.maven.ReducerMojo.java

License:Open Source License

@Override
protected void processFile(final File file) throws MojoFailureException {
    if (getLog().isDebugEnabled()) {
        getLog().debug("Running " + file + " through Reducer ...");
    }/*from w w w  . j  a  v  a 2 s . c  om*/

    if (!matryoshkaType.equalsIgnoreCase("quiet") && !matryoshkaType.equalsIgnoreCase("preloader")
            && !matryoshkaType.equalsIgnoreCase("custom")) {
        throw new MojoFailureException(
                "\"" + matryoshka + "\" is an illegal argument for the <matryoshkaType> node.");
    }

    final Reducer.ReducerTool tool = new Reducer.ReducerTool();
    final ReducerConfiguration config = new ReducerConfiguration() {
        @Override
        public File input() {
            return file;
        }

        @Override
        public File output() {
            return file;
        }

        @Override
        public float quality() {
            return quality;
        }

        @Override
        public float deblock() {
            return deblock;
        }

        @Override
        public boolean mergeABC() {
            return mergeABC;
        }

        @Override
        public boolean sortCPool() {
            return sortCPool;
        }

        @Override
        public boolean lzma() {
            return lzma;
        }

        @Override
        public int matryoshkaType() {
            if (matryoshkaType.equalsIgnoreCase("quiet")) {
                return MatryoshkaType.QUIET();
            } else if (matryoshkaType.equalsIgnoreCase("preloader")) {
                return MatryoshkaType.PRELOADER();
            } else if (matryoshkaType.equalsIgnoreCase("custom")) {
                return MatryoshkaType.CUSTOM();
            } else {
                return MatryoshkaType.NONE();
            }
        }

        @Override
        public Option<File> matryoshka() {
            return (null == matryoshka) ? None$.MODULE$ : new Some(matryoshka);
        }

        @Override
        public boolean mergeCF() {
            return mergeCF;
        }
    };

    tool.configure(config);
    tool.run();
}

From source file:at.peppol.maven.s2x.Schematron2XSLTMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    if (m_aSchematronDirectory == null)
        throw new MojoExecutionException("No Schematron directory specified!");
    if (m_aSchematronDirectory.exists() && !m_aSchematronDirectory.isDirectory())
        throw new MojoExecutionException(
                "The specified Schematron directory " + m_aSchematronDirectory + " is not a directory!");
    if (m_sSchematronPattern == null || m_sSchematronPattern.isEmpty()) {
        throw new MojoExecutionException("No Schematron pattern specified!");
    }//from   w  w w . j  a va2  s  .  co m
    if (m_aXSLTDirectory == null)
        throw new MojoExecutionException("No XSLT directory specified!");
    if (m_aXSLTDirectory.exists() && !m_aXSLTDirectory.isDirectory())
        throw new MojoExecutionException(
                "The specified XSLT directory " + m_aXSLTDirectory + " is not a directory!");
    if (m_sXSLTExtension == null || m_sXSLTExtension.length() == 0 || !m_sXSLTExtension.startsWith("."))
        throw new MojoExecutionException("The XSLT extension '" + m_sXSLTExtension + "' is invalid!");

    if (!m_aXSLTDirectory.exists() && !m_aXSLTDirectory.mkdirs())
        throw new MojoExecutionException("Failed to create the XSLT directory " + m_aXSLTDirectory);

    // for all Schematron files that match the pattern
    final DirectoryScanner aScanner = new DirectoryScanner();
    aScanner.setBasedir(m_aSchematronDirectory);
    aScanner.setIncludes(new String[] { m_sSchematronPattern });
    aScanner.setCaseSensitive(true);
    aScanner.scan();
    final String[] aFilenames = aScanner.getIncludedFiles();
    if (aFilenames != null) {
        for (final String sFilename : aFilenames) {
            final File aFile = new File(m_aSchematronDirectory, sFilename);

            // 1. build XSLT file name (outputdir + localpath with new extension)
            final File aXSLTFile = new File(m_aXSLTDirectory,
                    FilenameHelper.getWithoutExtension(sFilename) + m_sXSLTExtension);

            getLog().info("Converting Schematron file '" + aFile.getPath() + "' to XSLT file '"
                    + aXSLTFile.getPath() + "'");

            // 2. The Schematron resource
            final IReadableResource aSchematronResource = new FileSystemResource(aFile);

            // 3. Check if the XSLT file already exists
            if (aXSLTFile.exists() && !m_bOverwriteWithoutQuestion) {
                // 3.1 Not overwriting the existing file
                getLog().debug("Skipping XSLT file '" + aXSLTFile.getPath() + "' because it already exists!");
            } else {
                // 3.2 Create the directory, if necessary
                final File aXsltFileDirectory = aXSLTFile.getParentFile();
                if (aXsltFileDirectory != null && !aXsltFileDirectory.exists()) {
                    getLog().debug("Creating directory '" + aXsltFileDirectory.getPath() + "'");
                    if (!aXsltFileDirectory.mkdirs()) {
                        final String message = "Failed to convert '" + aFile.getPath() + "' because directory '"
                                + aXsltFileDirectory.getPath() + "' could not be created";
                        getLog().error(message);
                        throw new MojoFailureException(message);
                    }
                }
                // 3.3 Okay, write the XSLT file
                try {
                    // Custom error listener to log to the Mojo logger
                    final ErrorListener aMojoErrorListener = new AbstractTransformErrorListener(null) {
                        @Override
                        protected void internalLog(final IResourceError aResError) {
                            if (aResError.isError())
                                getLog().error(aResError.getAsString(Locale.US),
                                        aResError.getLinkedException());
                            else
                                getLog().warn(aResError.getAsString(Locale.US), aResError.getLinkedException());
                        }
                    };

                    // Custom error listener but no custom URI resolver
                    final ISchematronXSLTProvider aXsltProvider = SchematronResourceSCHCache
                            .createSchematronXSLTProvider(aSchematronResource, aMojoErrorListener, null);
                    if (aXsltProvider != null) {
                        // Write the resulting XSLT file to disk
                        XMLWriter.writeToStream(aXsltProvider.getXSLTDocument(),
                                new FileOutputStream(aXSLTFile), XMLWriterSettings.DEFAULT_XML_SETTINGS);
                    } else {
                        final String message = "Failed to convert '" + aFile.getPath()
                                + "': the Schematron resource is invalid";
                        getLog().error(message);
                        throw new MojoFailureException(message);
                    }
                } catch (final MojoFailureException up) {
                    throw up;
                } catch (final Exception ex) {
                    final String message = "Failed to convert '" + aFile.getPath() + "' to XSLT file '"
                            + aXSLTFile.getPath() + "'";
                    getLog().error(message, ex);
                    throw new MojoFailureException(message, ex);
                }
            }
        }
    }
}

From source file:au.com.acegi.xmlformat.XmlFormatPlugin.java

License:Apache License

@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void execute() throws MojoExecutionException, MojoFailureException {
    assert baseDirectory != null;
    assert targetDirectory != null;

    if (skip) {/*w  ww.ja v a2  s  .  c  om*/
        getLog().info("[xml-format] Skipped");
        return;
    }

    initializeIncludes();
    initializeExcludes();

    final OutputFormat fmt = buildFormatter();

    boolean success = true;
    for (final String inputName : find()) {
        final File input = new File(baseDirectory, inputName);
        final boolean changed;
        try {
            changed = formatInPlace(input, fmt);
        } catch (final DocumentException | IOException ex) {
            success = false;
            getLog().error("[xml-format] Error for " + input, ex);
            continue;
        }
        if (!getLog().isDebugEnabled()) {
            continue;
        }
        final String msg = changed ? "Formatted" : "Unchanged";
        getLog().debug("[xml-format] " + msg + ": " + input);
    }

    if (!success) {
        throw new MojoFailureException("[xml-format] Failed)");
    }
}

From source file:au.edu.usq.fascinator.maven_plugins.schemagen.RDF2Go.java

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Using RDF2Go to generate schema");
    for (String item : getSchema().keySet()) {
        getLog().info("Loading: " + item + " - " + getSchema().get(item));

        File schema;//from w  ww . j  a va 2 s . co  m
        try {
            File f = new File(System.getProperty("java.io.tmpdir"), item + ".xml");

            schema = downloadSchema(new URL(getSchema().get(item)), f.getAbsolutePath());
            getLog().info("Schema downloaded: " + schema.exists());
        } catch (IOException e) {
            throw new MojoFailureException(e.getMessage());
        }

        File outFolder = new File(getOutputFolder().getPath() + File.separator
                + getPackageName().replace('.', File.separatorChar));
        outFolder.mkdirs();

        String[] args = { "-i", schema.getAbsolutePath(), "-o", outFolder.getAbsolutePath(), "--package",
                getPackageName(), "-n", item, "-a", getSchema().get(item), "-namespacestrict",
                Boolean.toString(getNamespaceStrict()) };
        try {
            getLog().info("Calling VocabularyWriter for " + schema.getAbsolutePath());
            main(args);
            getLog().info("Completed VocabularyWriter for " + schema.getAbsolutePath());
        } catch (Exception e) {
            throw new MojoFailureException(e.getMessage());
        }
    }
}

From source file:be.idamediafoundry.sofa.livecycle.maven.AbstractLiveCycleMojo.java

License:Apache License

/**
 * Get the {@link ServiceClientFactory} for the given properties.
 * /*from   w w  w . j  ava2s.  com*/
 * @param host The host name/IP address of the destination LiveCycle server.
 * @param port The port number of the destination LiveCycle server.
 * @param protocol The protocol which should be used to communicate with the LiveCycle server. This can be EJB of
 *            SOAP.
 * @param username The user name used to login to the LiveCycle server.
 * @param password The password used to login to the LiveCycle server.
 * @return the {@link ServiceClientFactory} for the given properties
 * @throws MojoFailureException when one of the required parameters was not found.
 */
protected ServiceClientFactory getFactory(final String host, final String port, final String protocol,
        final String username, final String password) throws MojoFailureException {
    Properties connectionProps = new Properties();
    StringBuilder url = new StringBuilder();
    String protocolEndpointKey;
    if ("SOAP".equalsIgnoreCase(protocol)) {
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,
                ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);
        url.append("http://");

        protocolEndpointKey = ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT;
    } else if ("EJB".equalsIgnoreCase(protocol)) {
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,
                ServiceClientFactoryProperties.DSC_EJB_PROTOCOL);
        url.append("jnp://");

        protocolEndpointKey = ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT;
    } else {
        throw new MojoFailureException(protocol + " unknown.");
    }

    url.append(host).append(":").append(port);

    connectionProps.setProperty(protocolEndpointKey, url.toString());
    connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE,
            ServiceClientFactoryProperties.DSC_JBOSS_SERVER_TYPE);
    connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, username);
    connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, password);

    return ServiceClientFactory.createInstance(connectionProps);
}

From source file:be.idamediafoundry.sofa.livecycle.maven.ConfigurationMojo.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w  . jav a2s  .  com*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (configurationFile.exists()) {

        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(Config.class.getPackage().getName());
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            Config config = (Config) unmarshaller.unmarshal(configurationFile);
            ServiceClientFactory serviceClientFactory = getFactory();

            List<Service> services = config.getService();
            getLog().info("Setting configuration properties from " + configurationFile);
            for (Service service : services) {
                getLog().info("Configuring service " + service.getName());

                ServiceRegistryClient serviceReg = new ServiceRegistryClient(serviceClientFactory);
                ServiceConfiguration serviceConfiguration = serviceReg
                        .getHeadServiceConfiguration(service.getName());

                ModifyServiceConfigurationInfo modifyServiceConfigurationInfo = new ModifyServiceConfigurationInfo();
                String serviceId = serviceConfiguration.getServiceId();
                modifyServiceConfigurationInfo.setServiceId(serviceId);
                modifyServiceConfigurationInfo.setMajorVersion(serviceConfiguration.getMajorVersion());
                modifyServiceConfigurationInfo.setMinorVersion(serviceConfiguration.getMinorVersion());

                handleSecurity(service, serviceReg, modifyServiceConfigurationInfo, serviceId);

                handleConfigurationParameters(service, modifyServiceConfigurationInfo);

                getLog().info("Consolidating for service " + serviceId);
                serviceReg.modifyConfiguration(modifyServiceConfigurationInfo);

                handleEndpointConfiguration(serviceClientFactory, service.getEndpoints(), serviceId);
            }
        } catch (RegistryException e) {
            getLog().debug(e);
            throw new MojoFailureException("Application manager failure while configuring: " + e.getMessage());
        } catch (JAXBException e) {
            getLog().debug(e);
            throw new MojoFailureException("Configuration file could not be parsed: " + e.getMessage());
        }
    } else {
        throw new MojoFailureException("No configuration file found (I was looking at " + configurationFile
                + "), no configuration set");
    }
}

From source file:be.idamediafoundry.sofa.livecycle.maven.CopyContentSpaceMojo.java

License:Apache License

/**
 * {@inheritDoc}/*from  ww  w . j a  va  2s . c  o m*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (sourceContentSpacePath == null) {
        throw new MojoFailureException("The sourceContentSpacePath should be configured.");
    }

    if (contentSpacePath == null) {
        contentSpacePath = sourceContentSpacePath;
    }

    ServiceClientFactory sourceFactory = getFactory(sourceHost, sourcePort, sourceProtocol, sourceUsername,
            sourcePassword);
    ServiceClientFactory destinationFactory = getFactory();

    DocumentManagementServiceClient sourceDMSC = new DocumentManagementServiceClientImpl(sourceFactory);
    DocumentManagementServiceClient destinationDMSC = new DocumentManagementServiceClientImpl(
            destinationFactory);

    // TODO make params for storeName and versionLabel
    // Remove the content path on the destination server
    deepCopySpace(sourceContentSpacePath, contentSpacePath, sourceDMSC, destinationDMSC);
    // Start copying
    // CRCResult sourceContentCRCResult =
    // sourceDMSC.retrieveContent("SpacesStore", contentSpacePath, null);

    // System.out.println(sourceContentCRCResult.getNodeType());
}

From source file:be.idamediafoundry.sofa.livecycle.maven.CopyContentSpaceMojo.java

License:Apache License

/**
 * Deep copy the source path from the source content space to the destination path on the destination content space.
 * // w ww .  j a  v  a 2  s  .  c om
 * @param sourcePath the source path
 * @param destinationPath the destination path
 * @param sourceDMSC the source document management service (for reading)
 * @param destinationDMSC the destination document management service (for writing)
 * @throws MojoFailureException when copying fails
 */
private void deepCopySpace(final String sourcePath, final String destinationPath,
        final DocumentManagementServiceClient sourceDMSC, final DocumentManagementServiceClient destinationDMSC)
        throws MojoFailureException {
    try {
        prepareDestination(destinationPath, destinationDMSC);

        List<CRCResult> spaceContents = sourceDMSC.getSpaceContents("SpacesStore", sourcePath, Boolean.FALSE);
        for (CRCResult crcResult : spaceContents) {
            if (crcResult.getNodeType().equals(FOLDER_TYPE)) {
                deepCopySpace(sourcePath + "/" + crcResult.getNodeName(),
                        destinationPath + "/" + crcResult.getNodeName(), sourceDMSC, destinationDMSC);
            } else {
                copyContent(destinationPath, destinationDMSC, crcResult);
            }
        }

    } catch (CSAccessDeniedException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (CSAuthenticationException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (CSCommunicationException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (CSInvalidParameterException e) {
        throw new MojoFailureException(e.getMessage());
    } catch (ContentServicesException e) {
        throw new MojoFailureException(e.getMessage());
    }

}

From source file:be.idamediafoundry.sofa.livecycle.maven.CopyContentSpaceMojo.java

License:Apache License

/**
 * Prepare the destinaton path for writing to it.
 * //from ww  w  .j  av  a  2s  . c  o m
 * @param destinationPath the destination path to prepare
 * @param destinationDMSC the destination document management service
 * @throws CSAccessDeniedException when access is denied on the destination
 * @throws CSAuthenticationException when authentication fails on the destination
 * @throws CSCommunicationException when communication fails to the destination
 * @throws CSInvalidParameterException when invalid parameters are being passed to the destination
 * @throws ContentServicesException when writing content fails
 * @throws MojoFailureException when the path is not a folder
 * @throws CSInvocationException when content space invocation fails
 */
private void prepareDestination(final String destinationPath,
        final DocumentManagementServiceClient destinationDMSC)
        throws CSAccessDeniedException, CSAuthenticationException, CSCommunicationException,
        CSInvalidParameterException, ContentServicesException, MojoFailureException, CSInvocationException {
    try {
        CRCResult pathResult = destinationDMSC.retrieveContent("SpacesStore", destinationPath, null);

        if (!pathResult.getNodeType().equals(FOLDER_TYPE)) {
            throw new MojoFailureException("The source content space path is not a folder!");
        }
        getLog().info(destinationPath + " found on destination space");
    } catch (CSInvocationException e) {
        // It does not exist.
        getLog().info(destinationPath + " not found on destination space, creating ...");
        destinationDMSC.createSpace("SpacesStore", destinationPath);
    }
}