List of usage examples for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL
int VALIDATION_LEVEL_MINIMAL
To view the source code for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL.
Click Source Link
From source file:org.eclipse.aether.ant.AntRepoSys.java
License:Open Source License
public Model loadModel(Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories) { RepositorySystemSession session = getSession(task, null); remoteRepositories = remoteRepositories == null ? AetherUtils.getDefaultRepositories(project) : remoteRepositories;/* w ww . java 2s. c o m*/ List<org.eclipse.aether.repository.RemoteRepository> repositories = ConverterUtils .toRepositories(task.getProject(), session, remoteRepositories, getRemoteRepoMan()); ModelResolver modelResolver = new AntModelResolver(session, "project", getSystem(), getRemoteRepoMan(), repositories); Settings settings = getSettings(); try { DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setLocationTracking(true); request.setProcessPlugins(false); if (local) { request.setPomFile(pomFile); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT); } else { request.setModelSource(new FileModelSource(pomFile)); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); } request.setSystemProperties(getSystemProperties()); request.setUserProperties(getUserProperties()); request.setProfiles(SettingsUtils.convert(settings.getProfiles())); request.setActiveProfileIds(settings.getActiveProfiles()); request.setModelResolver(modelResolver); return modelBuilder.build(request).getEffectiveModel(); } catch (ModelBuildingException e) { throw new BuildException("Could not load POM " + pomFile + ": " + e.getMessage(), e); } }
From source file:org.eclipse.ebr.maven.ModelUtil.java
License:Open Source License
public Model buildEffectiveModel(final File pomFile) throws MojoExecutionException { getLog().debug(format("Building effective model for pom '%s'.", pomFile)); final DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setModelResolver(getModelResolver()); request.setPomFile(pomFile);//from ww w . j av a2 s . co m request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); request.setProcessPlugins(false); request.setTwoPhaseBuilding(false); request.setUserProperties(getMavenSession().getUserProperties()); request.setSystemProperties(getMavenSession().getSystemProperties()); if (getLog().isDebugEnabled()) { getLog().debug("Request: " + request); } ModelBuildingResult result; try { result = modelBuilder.build(request); } catch (final ModelBuildingException e) { getLog().debug(e); throw new MojoExecutionException( format("Unable to build model for pom '%s'. %s", pomFile, e.getMessage())); } if (getLog().isDebugEnabled()) { getLog().debug("Result: " + result); } return result.getEffectiveModel(); }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
public MavenProject readProject(final File pomFile, IProgressMonitor monitor) throws CoreException { return context().execute(new ICallable<MavenProject>() { public MavenProject call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException { MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(context.getExecutionRequest()); try { lookup(MavenExecutionRequestPopulator.class).populateDefaults(request); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); configuration.setRepositorySession(createRepositorySession(request)); return lookup(ProjectBuilder.class).build(pomFile, configuration).getProject(); } catch (ProjectBuildingException ex) { throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenImpl_error_read_project, ex)); } catch (MavenExecutionRequestPopulationException ex) { throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenImpl_error_read_project, ex)); }/*from w w w . ja v a 2 s .c om*/ } }, monitor); }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
@Deprecated /*package*/MavenExecutionResult readMavenProject(File pomFile, RepositorySystemSession repositorySession, MavenExecutionRequest request) throws CoreException { ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); configuration.setRepositorySession(repositorySession); return readMavenProject(pomFile, configuration); }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
public MavenExecutionResult readMavenProject(File pomFile, ProjectBuildingRequest configuration) throws CoreException { long start = System.currentTimeMillis(); log.debug("Reading Maven project: {}", pomFile.getAbsoluteFile()); //$NON-NLS-1$ MavenExecutionResult result = new DefaultMavenExecutionResult(); try {// ww w . j a v a 2 s.c om configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); ProjectBuildingResult projectBuildingResult = lookup(ProjectBuilder.class).build(pomFile, configuration); result.setProject(projectBuildingResult.getProject()); result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult()); } catch (ProjectBuildingException ex) { if (ex.getResults() != null && ex.getResults().size() == 1) { ProjectBuildingResult projectBuildingResult = ex.getResults().get(0); result.setProject(projectBuildingResult.getProject()); result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult()); } result.addException(ex); } finally { log.debug("Read Maven project: {} in {} ms", pomFile.getAbsoluteFile(), //$NON-NLS-1$ System.currentTimeMillis() - start); } return result; }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
MavenProject resolveParentProject(RepositorySystemSession repositorySession, MavenProject child, ProjectBuildingRequest configuration) throws CoreException { configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); configuration.setRepositorySession(repositorySession); try {//from w w w . j a va 2 s. com configuration.setRemoteRepositories(child.getRemoteArtifactRepositories()); File parentFile = child.getParentFile(); if (parentFile != null) { return lookup(ProjectBuilder.class).build(parentFile, configuration).getProject(); } Artifact parentArtifact = child.getParentArtifact(); if (parentArtifact != null) { return lookup(ProjectBuilder.class).build(parentArtifact, configuration).getProject(); } } catch (ProjectBuildingException ex) { log.error("Could not read parent project", ex); } return null; }
From source file:org.evosuite.maven.util.EvoSuiteRunner.java
License:Open Source License
/** * We run the EvoSuite that is provided with the plugin * //w w w . j a v a 2 s .c o m * @return */ private List<String> getCommandToRunEvoSuite() { logger.debug("EvoSuite Maven Plugin Artifacts: " + Arrays.toString(artifacts.toArray())); Artifact evosuite = null; for (Artifact art : artifacts) { //first find the main EvoSuite jar among the dependencies if (art.getArtifactId().equals("evosuite-master")) { evosuite = art; break; } } if (evosuite == null) { logger.error("CRITICAL ERROR: plugin can detect EvoSuite executable"); return null; } logger.debug("EvoSuite located at: " + evosuite.getFile()); /* * now, build a project descriptor for evosuite, which is needed to * query all of its dependencies */ DefaultProjectBuildingRequest req = new DefaultProjectBuildingRequest(); req.setRepositorySession(repoSession); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); req.setSystemProperties(System.getProperties()); req.setResolveDependencies(true); ProjectBuildingResult res; try { res = projectBuilder.build(evosuite, req); } catch (ProjectBuildingException e) { logger.error("Failed: " + e.getMessage(), e); return null; } //build the classpath to run EvoSuite String cp = evosuite.getFile().getAbsolutePath(); for (Artifact dep : res.getProject().getArtifacts()) { cp += File.pathSeparator + dep.getFile().getAbsolutePath(); } logger.debug("EvoSuite classpath: " + cp); String entryPoint = EvoSuite.class.getName(); List<String> cmd = new ArrayList<>(); cmd.add("java"); cmd.add("-D" + LoggingUtils.USE_DIFFERENT_LOGGING_XML_PARAMETER + "=logback-ctg-entry.xml"); cmd.add("-Dlogback.configurationFile=logback-ctg-entry.xml"); cmd.add("-cp"); cmd.add(cp); cmd.add(entryPoint); return cmd; }
From source file:org.metaservice.core.maven.MavenPomParser.java
License:Apache License
@Override public List<Model> parse(Reader s, ArchiveAddress archiveParameters) { File file = null;/*from ww w . jav a2 s . c om*/ try { file = File.createTempFile("temp", ".pom"); FileWriter writer = new FileWriter(file); IOUtils.copy(s, writer); writer.close(); ModelBuildingRequest req = new DefaultModelBuildingRequest(); req.setProcessPlugins(false); req.setPomFile(file); req.setModelResolver(makeModelResolver()); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory(); org.apache.maven.model.Model model = factory.newInstance().build(req).getEffectiveModel(); return Arrays.asList(model); } catch (IOException | ModelBuildingException e) { throw new RuntimeException(e); } finally { if (file != null && file.exists()) { file.delete(); } } }
From source file:org.ModelBuilderDemo.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//from www. j ava 2s . c o m * setup the container and get us some interesting components */ PlexusContainer container = new DefaultPlexusContainer(); ModelBuilder modelBuilder = container.lookup(ModelBuilder.class); ModelWriter modelWriter = container.lookup(ModelWriter.class); /* * build some effective model */ ModelSource modelSource = new UrlModelSource( ModelBuilderDemo.class.getResource("/repo/demo/dependency/1.0/pom.xml")); ModelBuildingRequest request = new DefaultModelBuildingRequest(); request.setModelSource(modelSource); request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); request.setSystemProperties(System.getProperties()); request.setModelResolver(new SimpleModelResolver()); ModelBuildingResult result = modelBuilder.build(request); Model effectivePom = result.getEffectiveModel(); StringWriter writer = new StringWriter(); modelWriter.write(writer, null, effectivePom); System.out.println(writer.toString()); }
From source file:org.nbheaven.sqe.core.maven.utils.MavenUtilities.java
License:Open Source License
/** * try to collect the plugin's dependency artifacts * as defined in <dependencies> section within <plugin>. Will only * return files currently in local repository * * @return list of files in local repository *///from ww w. j a va2 s . c om public static List<File> findDependencyArtifacts(Project project, String pluginGroupId, String pluginArtifactId, boolean includePluginArtifact) { List<File> cpFiles = new ArrayList<File>(); final NbMavenProject p = project.getLookup().lookup(NbMavenProject.class); final MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); MavenProject mp = p.getMavenProject(); if (includePluginArtifact) { Set<Artifact> arts = new HashSet<Artifact>(); arts.addAll(mp.getReportArtifacts()); arts.addAll(mp.getPluginArtifacts()); for (Artifact a : arts) { if (pluginArtifactId.equals(a.getArtifactId()) && pluginGroupId.equals(a.getGroupId())) { File f = a.getFile(); if (f == null) { //somehow the report plugins are not resolved, we need to workaround that.. f = FileUtil.normalizeFile(new File(new File(online.getLocalRepository().getBasedir()), online.getLocalRepository().pathOf(a))); } if (!f.exists()) { try { online.resolve(a, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); } catch (ArtifactResolutionException ex) { Exceptions.printStackTrace(ex); } catch (ArtifactNotFoundException ex) { Exceptions.printStackTrace(ex); } } if (f.exists()) { cpFiles.add(f); try { ProjectBuildingRequest req = new DefaultProjectBuildingRequest(); req.setRemoteRepositories(mp.getRemoteArtifactRepositories()); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); req.setSystemProperties(online.getSystemProperties()); ProjectBuildingResult res = online.buildProject(a, req); MavenProject mp2 = res.getProject(); if (mp2 != null) { // XXX this is not really right, but mp.dependencyArtifacts = null for some reason for (Dependency dep : mp2.getDependencies()) { Artifact a2 = online.createArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), "jar"); online.resolve(a2, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); File df = a2.getFile(); if (df.exists()) { cpFiles.add(df); } } } } catch (Exception x) { Exceptions.printStackTrace(x); } } } } } List<Plugin> plugins = mp.getBuildPlugins(); for (Plugin plug : plugins) { if (pluginArtifactId.equals(plug.getArtifactId()) && pluginGroupId.equals(plug.getGroupId())) { try { List<Dependency> deps = plug.getDependencies(); ArtifactFactory artifactFactory = online.getPlexus().lookup(ArtifactFactory.class); for (Dependency d : deps) { final Artifact projectArtifact = artifactFactory.createArtifactWithClassifier( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(), d.getClassifier()); String localPath = online.getLocalRepository().pathOf(projectArtifact); File f = FileUtil .normalizeFile(new File(online.getLocalRepository().getBasedir(), localPath)); if (!f.exists()) { try { online.resolve(projectArtifact, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); } catch (ArtifactResolutionException ex) { ex.printStackTrace(); // Exceptions.printStackTrace(ex); } catch (ArtifactNotFoundException ex) { ex.printStackTrace(); // Exceptions.printStackTrace(ex); } } if (f.exists()) { cpFiles.add(f); } } } catch (ComponentLookupException ex) { Exceptions.printStackTrace(ex); } } } return cpFiles; }