Search in sources :

Example 1 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project che by eclipse.

the class MavenServerImpl method loadExtensions.

private void loadExtensions(MavenProject project, List<Exception> exceptions) {
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    Collection<AbstractMavenLifecycleParticipant> participants = getLifecycleParticipants(Collections.singletonList(project));
    if (!participants.isEmpty()) {
        LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
        MavenSession session = legacySupport.getSession();
        session.setCurrentProject(project);
        session.setProjects(Collections.singletonList(project));
        for (AbstractMavenLifecycleParticipant participant : participants) {
            Thread.currentThread().setContextClassLoader(participant.getClass().getClassLoader());
            try {
                participant.afterProjectsRead(session);
            } catch (MavenExecutionException e) {
                exceptions.add(e);
            } finally {
                Thread.currentThread().setContextClassLoader(currentClassLoader);
            }
        }
    }
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionException(org.apache.maven.MavenExecutionException) LegacySupport(org.apache.maven.plugin.LegacySupport) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant)

Example 2 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project sling by apache.

the class LaunchpadPluginLifecycleParticipant method afterProjectsRead.

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    try {
        Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>();
        for (MavenProject project : session.getProjects()) {
            projectMap.put(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(), project);
        }
        for (MavenProject project : session.getProjects()) {
            for (Plugin plugin : project.getBuild().getPlugins()) {
                if (plugin.getArtifactId().equals(PLUGIN_ID)) {
                    BundleListDependencyAdder performer = new BundleListDependencyAdder(session, project, plugin);
                    performer.addDependencies();
                }
            }
        }
    } catch (Exception e) {
        throw new MavenExecutionException("Unable to determine launchpad plugin-based dependencies", e);
    }
    super.afterProjectsRead(session);
}
Also used : MavenExecutionException(org.apache.maven.MavenExecutionException) MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenExecutionException(org.apache.maven.MavenExecutionException) Plugin(org.apache.maven.model.Plugin)

Example 3 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project sling by apache.

the class PreparePackageMojo method getBaseArtifact.

/**
     * Return the base artifact
     */
private Artifact getBaseArtifact(final Model model, final String classifier, final String type) throws MojoExecutionException {
    try {
        final org.apache.sling.provisioning.model.Artifact baseArtifact = ModelUtils.findBaseArtifact(model);
        final Artifact a = ModelUtils.getArtifact(this.project, this.mavenSession, this.artifactHandlerManager, this.resolver, baseArtifact.getGroupId(), baseArtifact.getArtifactId(), baseArtifact.getVersion(), type, classifier);
        if (a == null) {
            throw new MojoExecutionException(String.format("Project doesn't have a base dependency of groupId %s and artifactId %s", baseArtifact.getGroupId(), baseArtifact.getArtifactId()));
        }
        return a;
    } catch (final MavenExecutionException mee) {
        throw new MojoExecutionException(mee.getMessage(), mee.getCause());
    }
}
Also used : MavenExecutionException(org.apache.maven.MavenExecutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project sling by apache.

the class ModelPreprocessor method processAttachments.

private void processAttachments(final Environment env, final ProjectInfo info) throws MavenExecutionException {
    final Xpp3Dom config = info.plugin == null ? null : (Xpp3Dom) info.plugin.getConfiguration();
    final Xpp3Dom[] nodes = (config == null ? null : config.getChildren("attach"));
    if (nodes != null) {
        for (final Xpp3Dom node : nodes) {
            final String type = nodeValue(node, "type", null);
            if (type == null) {
                throw new MavenExecutionException("Attachment for provisioning model has no type.", (File) null);
            }
            final String classifier = nodeValue(node, "classifier", null);
            final String featureName = nodeValue(node, "feature", null);
            int startLevel = 0;
            final String level = nodeValue(node, "startLevel", null);
            if (level != null) {
                startLevel = Integer.valueOf(level);
            }
            final Feature f;
            if (featureName != null) {
                f = info.localModel.getFeature(featureName);
            } else if (info.localModel.getFeatures().isEmpty()) {
                f = null;
            } else {
                f = info.localModel.getFeatures().get(0);
            }
            if (f == null) {
                if (featureName == null) {
                    throw new MavenExecutionException("No feature found in provisioning model for attachment.", (File) null);
                }
                throw new MavenExecutionException("Feature with name '" + featureName + "' not found in provisioning model for attachment.", (File) null);
            }
            final RunMode runMode = f.getOrCreateRunMode(null);
            final ArtifactGroup group = runMode.getOrCreateArtifactGroup(startLevel);
            final org.apache.sling.provisioning.model.Artifact artifact = new org.apache.sling.provisioning.model.Artifact(info.project.getGroupId(), info.project.getArtifactId(), info.project.getVersion(), classifier, type);
            env.logger.debug("Attaching " + artifact + " to feature " + f.getName());
            group.add(artifact);
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Feature(org.apache.sling.provisioning.model.Feature) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) MavenExecutionException(org.apache.maven.MavenExecutionException) RunMode(org.apache.sling.provisioning.model.RunMode) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup)

Example 5 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project tycho by eclipse.

the class WorkspaceTychoOsgiRuntimeLocator method addPlatformProperties.

public void addPlatformProperties(EquinoxRuntimeDescription result) throws MavenExecutionException {
    result.addPlatformProperty("osgi.install.area", stateLocation.getAbsolutePath());
    File devproperties = new File(stateLocation, "dev.properties");
    try {
        OutputStream os = new BufferedOutputStream(new FileOutputStream(devproperties));
        try {
            deventries.store(os, null);
        } finally {
            IOUtil.close(os);
        }
        result.addPlatformProperty("osgi.dev", devproperties.toURI().toURL().toExternalForm());
    } catch (IOException e) {
        throw new MavenExecutionException("Could not write dev.properties", e);
    }
}
Also used : MavenExecutionException(org.apache.maven.MavenExecutionException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

MavenExecutionException (org.apache.maven.MavenExecutionException)18 IOException (java.io.IOException)8 File (java.io.File)7 Artifact (org.apache.maven.artifact.Artifact)6 Model (org.apache.sling.provisioning.model.Model)5 Feature (org.apache.sling.provisioning.model.Feature)4 Traceable (org.apache.sling.provisioning.model.Traceable)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3 ArtifactGroup (org.apache.sling.provisioning.model.ArtifactGroup)3 RunMode (org.apache.sling.provisioning.model.RunMode)3 FileReader (java.io.FileReader)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 AbstractMavenLifecycleParticipant (org.apache.maven.AbstractMavenLifecycleParticipant)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 MavenSession (org.apache.maven.execution.MavenSession)2 Plugin (org.apache.maven.model.Plugin)2