List of usage examples for org.apache.maven MavenExecutionException MavenExecutionException
public MavenExecutionException(String message, Throwable cause)
From source file:kr.motd.maven.os.DetectExtension.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { Properties sessionProps = session.getSystemProperties(); // Detect the OS and CPU architecture. try {//from w ww . j ava 2s. c om detector.detect(sessionProps); } catch (DetectionException e) { throw new MavenExecutionException(e.getMessage(), session.getCurrentProject().getFile()); } // Generate the dictionary. Map<String, String> dict = new LinkedHashMap<String, String>(); dict.put(Detector.DETECTED_NAME, sessionProps.getProperty(Detector.DETECTED_NAME)); dict.put(Detector.DETECTED_ARCH, sessionProps.getProperty(Detector.DETECTED_ARCH)); dict.put(Detector.DETECTED_CLASSIFIER, sessionProps.getProperty(Detector.DETECTED_CLASSIFIER)); // Inject the current session. injectSession(session, dict); /// Perform the interpolation for the properties of all dependencies. for (MavenProject p : session.getProjects()) { interpolate(dict, p); } }
From source file:net.java.javabuild.MavenBuilderExtension.java
License:Apache License
private void addPluginExecutions(MavenProject project) throws MavenExecutionException { Properties properties = new Properties(); try {/*from w w w.j av a2s.c o m*/ properties.load(this.getClass().getResourceAsStream("version.properties")); } catch (IOException e) { throw new MavenExecutionException("Could not read plugin properties", e); } Plugin plugin = new Plugin(); plugin.setGroupId(properties.getProperty("groupId")); plugin.setArtifactId(properties.getProperty("artifactId")); plugin.setVersion(properties.getProperty("version")); addPluginExecution(plugin, "compile", Phase.GENERATE_SOURCES); addPluginExecution(plugin, "compile", Phase.PRE_SITE); Phase[] lifecyclePhases = Phase.values(); for (int i = 0; i < lifecyclePhases.length; i++) { addPluginExecution(plugin, "execute", lifecyclePhases[i]); } project.getBuild().addPlugin(plugin); }
From source file:org.apache.sling.maven.projectsupport.LaunchpadPluginLifecycleParticipant.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { try {/* w w w . java2 s . c om*/ 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); }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
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; }/*from w w w. j a v a2 s.co m*/ // prevent recursion and multiple processing info.done = true; env.logger.debug("Processing project " + info.project); // read local model final String directory = nodeValue(info.plugin, "modelDirectory", new File(info.project.getBasedir(), "src/main/provisioning").getAbsolutePath()); final String pattern = nodeValue(info.plugin, "modelPattern", "((.*)\\.txt|(.*)\\.model)"); final String inlinedModel = nodeValue(info.plugin, "model", null); try { info.localModel = readLocalModel(info.project, inlinedModel, new File(directory), pattern, env.logger); } catch (final IOException ioe) { throw new MavenExecutionException(ioe.getMessage(), ioe); } // 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))); } // we have to create an effective model to add the dependencies final Model effectiveModel = ModelUtility.getEffectiveModel(info.localModel, resolverOptions); final List<Model> dependencies = searchSlingstartDependencies(env, info, info.localModel, effectiveModel); info.model = new Model(); for (final Model d : dependencies) { this.mergeModels(info.model, d); } this.mergeModels(info.model, info.localModel); info.localModel = info.model; 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); } addDependenciesFromModel(env, info); try { ProjectHelper.storeProjectInfo(info); } catch (final IOException ioe) { throw new MavenExecutionException(ioe.getMessage(), ioe); } return info.model; }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
/** * Search for dependent slingstart/slingfeature artifacts and remove them from the effective model. * @throws MavenExecutionException//from w w w . j av a2 s. c o m */ 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<Model>(); 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<org.apache.sling.provisioning.model.Artifact>(); 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; }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
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); }// w ww. j ava 2s. co m 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; }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
private File resolveSlingstartArtifact(final Environment env, final MavenProject project, final Dependency d) throws MavenExecutionException { final Artifact prjArtifact = new DefaultArtifact(d.getGroupId(), d.getArtifactId(), VersionRange.createFromVersion(d.getVersion()), Artifact.SCOPE_PROVIDED, d.getType(), d.getClassifier(), env.artifactHandlerManager.getArtifactHandler(d.getType())); try {//from w ww . j a v a2 s . c o m env.resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), env.session.getLocalRepository()); } catch (final ArtifactResolutionException e) { throw new MavenExecutionException("Unable to get artifact for " + d, e); } catch (final ArtifactNotFoundException e) { throw new MavenExecutionException("Unable to get artifact for " + d, e); } return prjArtifact.getFile(); }
From source file:org.apache.sling.maven.slingstart.ModelPreprocessor.java
License:Apache License
/** * 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 modelDirectory The directory to scan for models * @param logger The logger//from w ww .j a v a 2s . c o m */ 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<String>(); 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); } ModelUtility.merge(result, current, 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); } ModelUtility.merge(result, current, 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); }
From source file:org.apache.sling.maven.slingstart.ModelUtils.java
License:Apache License
public static org.apache.sling.provisioning.model.Artifact findBaseArtifact(final Model model) throws MavenExecutionException { final Feature base = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD); if (base == null) { throw new MavenExecutionException("No launchpad feature found.", (File) null); } else {//from w w w. ja v a 2 s .c o m // get global run mode final RunMode runMode = base.getRunMode(); if (runMode == null) { throw new MavenExecutionException("No global run mode found in launchpad feature.", (File) null); } else { if (runMode.getArtifactGroups().isEmpty()) { throw new MavenExecutionException("No base artifacts defined.", (File) null); } else if (runMode.getArtifactGroups().size() > 1) { throw new MavenExecutionException("Base run mode should only have a single start level.", (File) null); } else { org.apache.sling.provisioning.model.Artifact firstArtifact = null; for (final org.apache.sling.provisioning.model.Artifact a : runMode.getArtifactGroups() .get(0)) { if (firstArtifact == null) { firstArtifact = a; } else { throw new MavenExecutionException("Base run mode should contain exactly one artifact: " + runMode.getArtifactGroups().get(0), (File) null); } } if (firstArtifact == null) { throw new MavenExecutionException("No base artifacts defined.", (File) null); } return firstArtifact; } } } }
From source file:org.codehaus.mojo.config.ConfigLifecycleParticipant.java
License:Open Source License
@Override public void afterProjectsRead(final MavenSession session) throws MavenExecutionException { try {/* w ww .j a v a 2 s . c om*/ final int totalModules = session.getProjects().size(); logger.info("Introspecting model with total of " + totalModules + " modules..."); for (MavenProject project : session.getProjects()) { Build build = project.getModel().getBuild(); final Map<String, Xpp3Dom> projectConfigurations = getProjectConfigurations(project); if (!projectConfigurations.isEmpty()) { logger.debug("{}", projectConfigurations); processPlugins(project, projectConfigurations, build.getPluginManagement()); processPlugins(project, projectConfigurations, build); } } } catch (IllegalArgumentException e) { throw new MavenExecutionException(groupId + ":" + artifactId + " error:\n " + e.getMessage(), e); } }