Search in sources :

Example 16 with MavenFilteringException

use of org.apache.maven.shared.filtering.MavenFilteringException in project sling by apache.

the class AbstractLaunchpadStartingMojo method executeWithArtifacts.

/**
     * {@inheritDoc}
     */
@Override
protected void executeWithArtifacts() throws MojoExecutionException {
    try {
        final Map<String, String> props = new HashMap<String, String>();
        props.put(SharedConstants.SLING_HOME, slingHome);
        // ensure launchpad is set
        props.put(SharedConstants.SLING_LAUNCHPAD, slingHome);
        if (forceBundleLoad) {
            props.put(SharedConstants.FORCE_PACKAGE_BUNDLE_LOADING, "true");
        }
        // set up and configure Felix Logger
        int logLevelNum;
        if (logLevel == null) {
            logLevelNum = DEFAULT_LOG_LEVEL;
        } else {
            logLevelNum = toLogLevelInt(logLevel, DEFAULT_LOG_LEVEL);
        }
        props.put(LOG_LEVEL_PROP, String.valueOf(logLevelNum));
        // Display port number on console, in case HttpService doesn't
        getLog().info("HTTP server port: " + httpPort);
        props.put(PROP_PORT, String.valueOf(httpPort));
        // prevent tons of needless WARN from the framework
        Logger logger = new Logger();
        logger.setLogLevel(Logger.LOG_ERROR);
        if (propertiesFile.exists()) {
            File tmp = null;
            try {
                tmp = File.createTempFile("sling", "props");
                mavenFileFilter.copyFile(propertiesFile, tmp, true, project, Collections.EMPTY_LIST, true, System.getProperty("file.encoding"), mavenSession);
                Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
                for (Object key : loadedProps.keySet()) {
                    props.put((String) key, (String) loadedProps.get(key));
                }
            } catch (IOException e) {
                throw new MojoExecutionException("Unable to create filtered properties file", e);
            } catch (MavenFilteringException e) {
                throw new MojoExecutionException("Unable to create filtered properties file", e);
            } finally {
                if (tmp != null) {
                    tmp.delete();
                }
            }
        }
        sling = startSling(resourceProvider, props, logger);
    } catch (BundleException be) {
        getLog().error("Failed to Start OSGi framework", be);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) Logger(org.apache.felix.framework.Logger) Properties(java.util.Properties) File(java.io.File)

Example 17 with MavenFilteringException

use of org.apache.maven.shared.filtering.MavenFilteringException in project sling by apache.

the class AbstractUsingBundleListMojo method readSlingBootstrap.

/**
     * Try to read the bootstrap command file
     * The filter is copied to a tmp location to apply filtering.
     * @throws MojoExecutionException
     */
private void readSlingBootstrap(final File bootstrapFile, final int mode) throws MojoExecutionException {
    if (bootstrapFile.exists()) {
        File tmp = null;
        Reader reader = null;
        try {
            tmp = File.createTempFile("sling", "bootstrap");
            mavenFileFilter.copyFile(bootstrapFile, tmp, true, project, Collections.EMPTY_LIST, true, System.getProperty("file.encoding"), mavenSession);
            reader = new FileReader(tmp);
            final StringBuilder sb = new StringBuilder();
            if (mode == 0) {
                if (this.slingBootstrapCommand != null) {
                    sb.append(this.slingBootstrapCommand);
                }
            } else if (mode == 1) {
                if (this.slingWebappBootstrapCommand != null) {
                    sb.append(this.slingWebappBootstrapCommand);
                }
            } else {
                if (this.slingStandaloneBootstrapCommand != null) {
                    sb.append(this.slingStandaloneBootstrapCommand);
                }
            }
            final char[] buffer = new char[2048];
            int l;
            while ((l = reader.read(buffer, 0, buffer.length)) != -1) {
                sb.append(buffer, 0, l);
            }
            sb.append('\n');
            if (mode == 0) {
                this.slingBootstrapCommand = sb.toString();
            } else if (mode == 1) {
                this.slingWebappBootstrapCommand = sb.toString();
            } else {
                this.slingStandaloneBootstrapCommand = sb.toString();
            }
        } catch (final IOException e) {
            throw new MojoExecutionException("Unable to create filtered bootstrap file", e);
        } catch (final MavenFilteringException e) {
            throw new MojoExecutionException("Unable to create filtered bootstrap file", e);
        } finally {
            if (tmp != null) {
                tmp.delete();
            }
            if (reader != null) {
                try {
                    reader.close();
                } catch (final IOException ignore) {
                }
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 18 with MavenFilteringException

use of org.apache.maven.shared.filtering.MavenFilteringException in project project-build-plugin by axonivy.

the class DeploymentOptionsFileFactory method createFromTemplate.

public File createFromTemplate(File optionsFile, MavenProject project, MavenSession session, MavenFileFilter fileFilter) throws MojoExecutionException {
    if (!isOptionsFile(optionsFile)) {
        return null;
    }
    String fileFormat = FilenameUtils.getExtension(optionsFile.getName());
    File targetFile = getTargetFile(fileFormat);
    try {
        fileFilter.copyFile(optionsFile, targetFile, true, project, Collections.emptyList(), false, StandardCharsets.UTF_8.name(), session);
    } catch (MavenFilteringException ex) {
        throw new MojoExecutionException("Failed to resolve templates in options file", ex);
    }
    return targetFile;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) File(java.io.File)

Aggregations

MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)18 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 File (java.io.File)12 IOException (java.io.IOException)10 MavenResourcesExecution (org.apache.maven.shared.filtering.MavenResourcesExecution)6 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 MavenArchiver (org.apache.maven.archiver.MavenArchiver)3 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)3 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)3 FileReader (java.io.FileReader)2 Reader (java.io.Reader)2 LinkedHashSet (java.util.LinkedHashSet)2 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)2 Resource (org.apache.maven.model.Resource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenFileFilterRequest (org.apache.maven.shared.filtering.MavenFileFilterRequest)2 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1