use of org.apache.maven.MavenExecutionException in project sling by apache.
the class ModelPreprocessor method addDependencies.
/**
* Add dependencies for a single project.
* @param env The environment with all maven settings and projects
* @param info The project to process.
* @throws MavenExecutionException If anything goes wrong.
*/
private Model addDependencies(final Environment env, final ProjectInfo info) throws MavenExecutionException {
if (info.done == true) {
env.logger.debug("Return prepared model for " + info.project);
return info.model;
}
// prevent recursion and multiple processing
info.done = true;
env.logger.debug("Processing project " + info.project);
// read local model
final String pattern = nodeValue(info.plugin, "modelPattern", AbstractSlingStartMojo.DEFAULT_MODEL_PATTERN);
final String inlinedModel = nodeValue(info.plugin, "model", null);
String scope = Artifact.SCOPE_PROVIDED;
try {
if (hasNodeValue(info.plugin, "modelDirectory")) {
final String directory = nodeValue(info.plugin, "modelDirectory", null);
info.localModel = readLocalModel(info.project, inlinedModel, new File(directory), pattern, env.logger);
} else {
// use multiple fallbacks here only in case the default model directory is not explicitly set
File defaultModelDirectory = new File(info.project.getBasedir(), "src/main/provisioning");
if (defaultModelDirectory.exists()) {
env.logger.debug("Try to extract model from default provisioning directory " + defaultModelDirectory.getAbsolutePath());
info.localModel = readLocalModel(info.project, inlinedModel, defaultModelDirectory, pattern, env.logger);
} else {
File defaultModelDirectoryInTest = new File(info.project.getBasedir(), "src/test/provisioning");
env.logger.debug("Try to extract model from default test provisioning directory " + defaultModelDirectoryInTest.getAbsolutePath());
info.localModel = readLocalModel(info.project, inlinedModel, defaultModelDirectoryInTest, pattern, env.logger);
scope = Artifact.SCOPE_TEST;
}
}
} catch (final IOException ioe) {
throw new MavenExecutionException(ioe.getMessage(), ioe);
}
// process attachments
processAttachments(env, info);
// is the maven classpath supposed to be extended?
info.extendMavenClassPath = !nodeBooleanValue(info.plugin, AbstractSlingStartMojo.CONFIGURATION_NAME_DISABLE_EXTENDING_CLASSPATH, false);
// check for setting version
if (nodeBooleanValue(info.plugin, "setFeatureVersions", false)) {
for (final Feature f : info.localModel.getFeatures()) {
if (f.getVersion() == null) {
f.setVersion(cleanupVersion(info.project.getVersion()));
}
}
}
// prepare resolver options
ResolverOptions resolverOptions = new ResolverOptions();
if (nodeBooleanValue(info.plugin, "usePomVariables", false)) {
resolverOptions.variableResolver(new PomVariableResolver(info.project));
}
if (nodeBooleanValue(info.plugin, "usePomDependencies", false)) {
resolverOptions.artifactVersionResolver(new PomArtifactVersionResolver(info.project, nodeBooleanValue(info.plugin, "allowUnresolvedPomDependencies", false)));
}
final Model copyModel = new Model();
this.mergeModels(copyModel, info.localModel);
// we have to create an effective model to add the dependencies
final Model effectiveModel = ModelUtility.getEffectiveModel(copyModel, resolverOptions);
final List<Model> dependencies = searchSlingstartDependencies(env, info, copyModel, effectiveModel);
info.model = new Model();
for (final Model d : dependencies) {
this.mergeModels(info.model, d);
}
this.mergeModels(info.model, copyModel);
info.model = ModelUtility.getEffectiveModel(info.model, resolverOptions);
final Map<Traceable, String> errors = ModelUtility.validate(info.model);
if (errors != null) {
throw new MavenExecutionException("Unable to create model file for " + info.project + " : " + errors, (File) null);
}
if (info.extendMavenClassPath) {
addDependenciesFromModel(env, info, scope);
env.logger.info("Extended Maven classpath (scope '" + scope + "') by the dependencies extracted from the Sling model.");
} else {
env.logger.debug("Do not enrich Maven classpath with Sling model!");
}
try {
ProjectHelper.storeProjectInfo(info);
} catch (final IOException ioe) {
throw new MavenExecutionException(ioe.getMessage(), ioe);
}
return info.model;
}
use of org.apache.maven.MavenExecutionException in project sling by apache.
the class RepositoryMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final File artifactDir = new File(this.project.getBuild().getDirectory(), DIR_NAME);
this.getLog().info("Creating repository in '" + artifactDir.getPath() + "'...");
// artifacts
final Model model = ProjectHelper.getEffectiveModel(this.project, getResolverOptions());
for (final Feature feature : model.getFeatures()) {
for (final RunMode runMode : feature.getRunModes()) {
for (final ArtifactGroup group : runMode.getArtifactGroups()) {
for (final org.apache.sling.provisioning.model.Artifact artifact : group) {
copyArtifactToRepository(artifact, artifactDir);
}
}
}
}
// base artifact - only if launchpad feature is available
if (model.getFeature(ModelConstants.FEATURE_LAUNCHPAD) != null) {
try {
final org.apache.sling.provisioning.model.Artifact baseArtifact = ModelUtils.findBaseArtifact(model);
final org.apache.sling.provisioning.model.Artifact appArtifact = new org.apache.sling.provisioning.model.Artifact(baseArtifact.getGroupId(), baseArtifact.getArtifactId(), baseArtifact.getVersion(), BuildConstants.CLASSIFIER_APP, BuildConstants.TYPE_JAR);
copyArtifactToRepository(appArtifact, artifactDir);
} catch (final MavenExecutionException mee) {
throw new MojoExecutionException(mee.getMessage(), mee.getCause());
}
}
// models
Model rawModel = ProjectHelper.getRawModel(this.project);
if (usePomVariables) {
rawModel = ModelUtility.applyVariables(rawModel, new PomVariableResolver(project));
}
if (usePomDependencies) {
rawModel = ModelUtility.applyArtifactVersions(rawModel, new PomArtifactVersionResolver(project, allowUnresolvedPomDependencies));
}
final String classifier = (project.getPackaging().equals(BuildConstants.PACKAGING_PARTIAL_SYSTEM) ? null : BuildConstants.PACKAGING_PARTIAL_SYSTEM);
final org.apache.sling.provisioning.model.Artifact rawModelArtifact = new org.apache.sling.provisioning.model.Artifact(this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(), classifier, BuildConstants.TYPE_TXT);
final File rawModelFile = getRepositoryFile(artifactDir, rawModelArtifact);
Writer writer = null;
try {
writer = new FileWriter(rawModelFile);
ModelWriter.write(writer, rawModel);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write model to " + rawModelFile, e);
} finally {
IOUtils.closeQuietly(writer);
}
// and write model to target
writer = null;
try {
writer = new FileWriter(new File(this.project.getBuild().getDirectory(), repositoryModelName));
ModelWriter.write(writer, rawModel);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write model to " + rawModelFile, e);
} finally {
IOUtils.closeQuietly(writer);
}
for (final Map.Entry<String, String> entry : ProjectHelper.getDependencyModel(this.project).entrySet()) {
final org.apache.sling.provisioning.model.Artifact modelDepArtifact = org.apache.sling.provisioning.model.Artifact.fromMvnUrl(entry.getKey());
final String modelClassifier = (modelDepArtifact.getType().equals(BuildConstants.PACKAGING_SLINGSTART) ? BuildConstants.PACKAGING_PARTIAL_SYSTEM : modelDepArtifact.getClassifier());
final org.apache.sling.provisioning.model.Artifact modelArtifact = new org.apache.sling.provisioning.model.Artifact(modelDepArtifact.getGroupId(), modelDepArtifact.getArtifactId(), modelDepArtifact.getVersion(), modelClassifier, BuildConstants.TYPE_TXT);
final File modelFile = getRepositoryFile(artifactDir, modelArtifact);
Writer modelWriter = null;
try {
modelWriter = new FileWriter(modelFile);
modelWriter.write(entry.getValue());
} catch (IOException e) {
throw new MojoExecutionException("Unable to write model to " + modelFile, e);
} finally {
IOUtils.closeQuietly(modelWriter);
}
}
}
use of org.apache.maven.MavenExecutionException in project sling by apache.
the class ModelPreprocessor method processSlingstartDependencies.
private Model processSlingstartDependencies(final Environment env, final ProjectInfo info, final Dependency dep, final Model rawModel) throws MavenExecutionException {
env.logger.debug("Processing dependency " + dep);
// we have to create an effective model to add the dependencies
final Model effectiveModel = ModelUtility.getEffectiveModel(rawModel, new ResolverOptions());
final List<Model> dependencies = searchSlingstartDependencies(env, info, rawModel, effectiveModel);
Model mergingModel = new Model();
for (final Model d : dependencies) {
this.mergeModels(mergingModel, d);
}
this.mergeModels(mergingModel, rawModel);
final Map<Traceable, String> errors = ModelUtility.validate(ModelUtility.getEffectiveModel(mergingModel, new ResolverOptions()));
if (errors != null) {
throw new MavenExecutionException("Unable to create model file for " + dep + " : " + errors, (File) null);
}
return mergingModel;
}
use of org.apache.maven.MavenExecutionException in project tycho by eclipse.
the class WorkspaceTychoOsgiRuntimeLocator method addProduct.
public boolean addProduct(EquinoxRuntimeDescription result, Artifact pom) throws MavenExecutionException {
ProductConfiguration product;
try {
product = ProductConfiguration.read(new File(pom.getFile().getParentFile(), pom.getArtifactId() + ".product"));
} catch (IOException e) {
return false;
}
// the above fails with IOException if .product file is not available or can't be read
// we get here only when we have valid product instance
Set<String> missing = new LinkedHashSet<>();
for (PluginRef pluginRef : product.getPlugins()) {
DevBundleInfo bundleInfo = workspaceState.getBundleInfo(pluginRef.getId(), pluginRef.getVersion());
if (bundleInfo != null) {
addBundle(result, bundleInfo);
} else {
missing.add(pluginRef.toString());
}
}
if (!missing.isEmpty()) {
throw new MavenExecutionException("Inconsistent m2e-tycho workspace state, missing bundles: " + missing.toString(), (Throwable) null);
}
Map<String, BundleConfiguration> bundleConfigurations = product.getPluginConfiguration();
if (bundleConfigurations != null) {
for (BundleConfiguration bundleConfiguration : bundleConfigurations.values()) {
result.addBundleStartLevel(bundleConfiguration.getId(), bundleConfiguration.getStartLevel(), bundleConfiguration.isAutoStart());
}
}
return true;
}
use of org.apache.maven.MavenExecutionException in project tycho by eclipse.
the class TychoMavenLifecycleParticipant method validateConsistentTychoVersion.
protected void validateConsistentTychoVersion(List<MavenProject> projects) throws MavenExecutionException {
Map<String, Set<MavenProject>> versionToProjectsMap = new HashMap<>();
for (MavenProject project : projects) {
for (Plugin plugin : project.getBuild().getPlugins()) {
if (TYCHO_GROUPID.equals(plugin.getGroupId()) && TYCHO_PLUGIN_IDS.contains(plugin.getArtifactId())) {
String version = plugin.getVersion();
// Skip checking plug ins that do not have a version
if (version == null) {
continue;
}
log.debug(TYCHO_GROUPID + ":" + plugin.getArtifactId() + ":" + version + " configured in " + project);
Set<MavenProject> projectSet = versionToProjectsMap.get(version);
if (projectSet == null) {
projectSet = new LinkedHashSet<>();
versionToProjectsMap.put(version, projectSet);
}
projectSet.add(project);
}
}
}
if (versionToProjectsMap.size() > 1) {
List<String> versions = new ArrayList<>(versionToProjectsMap.keySet());
Collections.sort(versions);
log.error("Several versions of tycho plugins are configured " + versions + ":");
for (String version : versions) {
log.error(version + ":");
for (MavenProject project : versionToProjectsMap.get(version)) {
log.error("\t" + project.toString());
}
}
throw new MavenExecutionException("All tycho plugins configured in one reactor must use the same version", projects.get(0).getFile());
}
}
Aggregations