Search in sources :

Example 6 with MavenExecutionException

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

the class P2DependencyResolver method getDependencyMetadata.

protected Map<String, IDependencyMetadata> getDependencyMetadata(final MavenSession session, final MavenProject project, final List<TargetEnvironment> environments, final OptionalResolutionAction optionalAction) {
    final Map<String, IDependencyMetadata> metadata = new LinkedHashMap<>();
    metadata.put(null, generator.generateMetadata(new AttachedArtifact(project, project.getBasedir(), null), environments, optionalAction));
    // let external providers contribute additional metadata
    try {
        pluginRealmHelper.execute(session, project, new Runnable() {

            @Override
            public void run() {
                try {
                    for (P2MetadataProvider provider : plexus.lookupList(P2MetadataProvider.class)) {
                        Map<String, IDependencyMetadata> providedMetadata = provider.getDependencyMetadata(session, project, null, optionalAction);
                        if (providedMetadata != null) {
                            metadata.putAll(providedMetadata);
                        }
                    }
                } catch (ComponentLookupException e) {
                // have not found anything
                }
            }
        }, new PluginFilter() {

            @Override
            public boolean accept(PluginDescriptor descriptor) {
                return isTychoP2Plugin(descriptor);
            }
        });
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    }
    return metadata;
}
Also used : PluginFilter(org.eclipse.tycho.core.maven.utils.PluginRealmHelper.PluginFilter) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) AttachedArtifact(org.eclipse.tycho.p2.facade.internal.AttachedArtifact) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenExecutionException(org.apache.maven.MavenExecutionException) IDependencyMetadata(org.eclipse.tycho.p2.metadata.IDependencyMetadata) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with MavenExecutionException

use of org.apache.maven.MavenExecutionException in project pom-manipulation-ext by release-engineering.

the class ManipulatingLifeCycleParticipant method afterProjectsRead.

@Override
public void afterProjectsRead(final MavenSession mavenSession) throws MavenExecutionException {
    final ManipulationException error = session.getError();
    if (error != null) {
        throw new MavenExecutionException("POM Manipulation failed: " + error.getMessage(), error);
    }
    super.afterProjectsRead(mavenSession);
}
Also used : MavenExecutionException(org.apache.maven.MavenExecutionException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException)

Example 8 with MavenExecutionException

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

the class MavenServerImpl method runMavenRequest.

public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
    MavenSession mavenSession = new MavenSession(container, repositorySystemSession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
    MavenSession previousSession = legacySupport.getSession();
    legacySupport.setSession(mavenSession);
    try {
        for (AbstractMavenLifecycleParticipant participant : getLifecycleParticipants(Collections.emptyList())) {
            participant.afterSessionStart(mavenSession);
        }
        runnable.run();
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    } finally {
        legacySupport.setSession(previousSession);
    }
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionException(org.apache.maven.MavenExecutionException) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant) DefaultMaven(org.apache.maven.DefaultMaven)

Example 9 with MavenExecutionException

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

the class ModelPreprocessor method readLocalModel.

/**
     * Read all model files from the directory in alphabetical order.
     * Only files ending with .txt or .model are read.
     *
     * @param project The current maven project
     * @param inlinedModel the inlined model to be merged with the models in modelDirectory (may be null)
     * @param modelDirectory The directory to scan for models
     * @param pattern Pattern used to find the textual models within the modelDirectory
     * @param logger The logger
     */
protected Model readLocalModel(final MavenProject project, final String inlinedModel, final File modelDirectory, final String pattern, final Logger logger) throws MavenExecutionException, IOException {
    final Pattern p = Pattern.compile(pattern);
    final List<String> candidates = new ArrayList<>();
    if (modelDirectory != null && modelDirectory.exists()) {
        for (final File f : modelDirectory.listFiles()) {
            if (f.isFile() && !f.getName().startsWith(".")) {
                if (p.matcher(f.getName()).matches()) {
                    candidates.add(f.getName());
                }
            }
        }
        Collections.sort(candidates);
    }
    if (candidates.size() == 0 && (inlinedModel == null || inlinedModel.trim().length() == 0)) {
        throw new MavenExecutionException("No model files found in " + modelDirectory + ", and no model inlined in POM.", (File) null);
    }
    final Model result = new Model();
    if (inlinedModel != null) {
        logger.debug("Reading inlined model from project " + project.getId());
        try {
            final Reader reader = new StringReader(inlinedModel);
            try {
                final Model current = ModelReader.read(reader, "pom");
                final Map<Traceable, String> errors = ModelUtility.validate(current);
                if (errors != null) {
                    throw new MavenExecutionException("Invalid inlined model : " + errors, (File) null);
                }
                MergeUtility.merge(result, current, new MergeUtility.MergeOptions().setHandleRemoveRunMode(false));
            } finally {
                IOUtils.closeQuietly(reader);
            }
        } catch (final IOException io) {
            throw new MavenExecutionException("Unable to read inlined model", io);
        }
    }
    for (final String name : candidates) {
        logger.debug("Reading model " + name + " in project " + project.getId());
        try {
            final File f = new File(modelDirectory, name);
            final FileReader reader = new FileReader(f);
            try {
                final Model current = ModelReader.read(reader, f.getAbsolutePath());
                final Map<Traceable, String> errors = ModelUtility.validate(current);
                if (errors != null) {
                    throw new MavenExecutionException("Invalid model at " + name + " : " + errors, (File) null);
                }
                MergeUtility.merge(result, current, new MergeUtility.MergeOptions().setHandleRemoveRunMode(false));
            } finally {
                IOUtils.closeQuietly(reader);
            }
        } catch (final IOException io) {
            throw new MavenExecutionException("Unable to read model at " + name, io);
        }
    }
    final Map<Traceable, String> errors = ModelUtility.validate(result);
    if (errors != null) {
        throw new MavenExecutionException("Invalid assembled model : " + errors, (File) null);
    }
    return postProcessReadModel(result);
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) FileReader(java.io.FileReader) ModelReader(org.apache.sling.provisioning.model.io.ModelReader) IOException(java.io.IOException) MavenExecutionException(org.apache.maven.MavenExecutionException) Model(org.apache.sling.provisioning.model.Model) StringReader(java.io.StringReader) FileReader(java.io.FileReader) Traceable(org.apache.sling.provisioning.model.Traceable) File(java.io.File)

Example 10 with MavenExecutionException

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

the class ModelPreprocessor method searchSlingstartDependencies.

/**
     * Search for dependent slingstart/slingfeature artifacts and remove them from the effective model.
     * @throws MavenExecutionException
     */
private List<Model> searchSlingstartDependencies(final Environment env, final ProjectInfo info, final Model rawModel, final Model effectiveModel) throws MavenExecutionException {
    // slingstart or slingfeature
    final List<Model> dependencies = new ArrayList<>();
    for (final Feature feature : effectiveModel.getFeatures()) {
        for (final RunMode runMode : feature.getRunModes()) {
            for (final ArtifactGroup group : runMode.getArtifactGroups()) {
                final List<org.apache.sling.provisioning.model.Artifact> removeList = new ArrayList<>();
                for (final org.apache.sling.provisioning.model.Artifact a : group) {
                    if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART) || a.getType().equals(BuildConstants.PACKAGING_PARTIAL_SYSTEM)) {
                        final Dependency dep = new Dependency();
                        dep.setGroupId(a.getGroupId());
                        dep.setArtifactId(a.getArtifactId());
                        dep.setVersion(a.getVersion());
                        dep.setType(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
                        if (a.getType().equals(BuildConstants.PACKAGING_SLINGSTART)) {
                            dep.setClassifier(BuildConstants.PACKAGING_PARTIAL_SYSTEM);
                        } else {
                            dep.setClassifier(a.getClassifier());
                        }
                        dep.setScope(Artifact.SCOPE_PROVIDED);
                        env.logger.debug("- adding dependency " + ModelUtils.toString(dep));
                        info.project.getDependencies().add(dep);
                        // if it's a project from the current reactor build, we can't resolve it right now
                        final String key = a.getGroupId() + ":" + a.getArtifactId();
                        final ProjectInfo depInfo = env.modelProjects.get(key);
                        if (depInfo != null) {
                            env.logger.debug("Found reactor " + a.getType() + " dependency : " + a);
                            final Model model = addDependencies(env, depInfo);
                            if (model == null) {
                                throw new MavenExecutionException("Recursive model dependency list including project " + info.project, (File) null);
                            }
                            dependencies.add(model);
                            info.includedModels.put(a, depInfo.localModel);
                        } else {
                            env.logger.debug("Found external " + a.getType() + " dependency: " + a);
                            // "external" dependency, we can already resolve it
                            final File modelFile = resolveSlingstartArtifact(env, info.project, dep);
                            FileReader r = null;
                            try {
                                r = new FileReader(modelFile);
                                final Model model = ModelReader.read(r, modelFile.getAbsolutePath());
                                info.includedModels.put(a, model);
                                final Map<Traceable, String> errors = ModelUtility.validate(model);
                                if (errors != null) {
                                    throw new MavenExecutionException("Unable to read model file from " + modelFile + " : " + errors, modelFile);
                                }
                                final Model fullModel = processSlingstartDependencies(env, info, dep, model);
                                dependencies.add(fullModel);
                            } catch (final IOException ioe) {
                                throw new MavenExecutionException("Unable to read model file from " + modelFile, ioe);
                            } finally {
                                try {
                                    if (r != null) {
                                        r.close();
                                    }
                                } catch (final IOException io) {
                                // ignore
                                }
                            }
                        }
                        removeList.add(a);
                    }
                }
                for (final org.apache.sling.provisioning.model.Artifact r : removeList) {
                    group.remove(r);
                    final Feature localModelFeature = rawModel.getFeature(feature.getName());
                    if (localModelFeature != null) {
                        final RunMode localRunMode = localModelFeature.getRunMode(runMode.getNames());
                        if (localRunMode != null) {
                            final ArtifactGroup localAG = localRunMode.getArtifactGroup(group.getStartLevel());
                            if (localAG != null) {
                                localAG.remove(r);
                            }
                        }
                    }
                }
            }
        }
    }
    return dependencies;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) 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) Model(org.apache.sling.provisioning.model.Model) FileReader(java.io.FileReader) Traceable(org.apache.sling.provisioning.model.Traceable) ArtifactGroup(org.apache.sling.provisioning.model.ArtifactGroup) File(java.io.File)

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