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;
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations