List of usage examples for org.apache.maven.model.io DefaultModelReader DefaultModelReader
DefaultModelReader
From source file:br.com.uggeri.maven.builder.mojo.DependencyResolver.java
public List<Artifact> resolveDependencies(MavenProject project, Artifact artifact) throws MojoExecutionException { final List<Artifact> artifactDependencies = new ArrayList<Artifact>(); Artifact pomArtifact = createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom"); resolveArtifact(project, pomArtifact); if (pomArtifact.isResolved()) { DefaultModelReader dmr = new DefaultModelReader(); try {/*from w w w . jav a2 s .co m*/ Model pomModel = dmr.read(pomArtifact.getFile(), null); for (Dependency dep : pomModel.getDependencies()) { final Artifact depArtifact = createArtifact(dep); if (log != null && log.isDebugEnabled()) { log.debug("Dependencia encontrada para " + artifact.getId() + "."); } resolveArtifact(project, depArtifact); if (depArtifact.isResolved()) { artifactDependencies.add(depArtifact); } } } catch (IOException ex) { throw new MojoExecutionException("Erro ao ler o arquivo POM do artefato " + artifact.getId(), ex); } } return artifactDependencies; }
From source file:com.google.devtools.build.workspace.maven.Resolver.java
License:Open Source License
/** * Given a local path to a Maven project, this attempts to find the transitive dependencies of * the project.//from www. j ava 2s. c om * @param projectPath The path to search for Maven projects. */ public String resolvePomDependencies(String projectPath) { DefaultModelProcessor processor = new DefaultModelProcessor(); processor.setModelLocator(new DefaultModelLocator()); processor.setModelReader(new DefaultModelReader()); File pom = processor.locatePom(new File(projectPath)); FileModelSource pomSource = new FileModelSource(pom); // First resolve the model source locations. resolveSourceLocations(pomSource); // Next, fully resolve the models. resolveEffectiveModel(pomSource, Sets.<String>newHashSet(), null); return pom.getAbsolutePath(); }
From source file:net.flowas.codegen.model.MavenFilter.java
License:Apache License
@Override public byte[] filte(String fileName, byte[] data) { file = fileName;//from www.j a v a2 s. c om if (file.contains("pom.xml")) { DependencyFacet maven = project.getFacet(DependencyFacet.class); DefaultModelReader r = new DefaultModelReader(); try { Model model = r.read(new ByteArrayInputStream(data), null); List<Dependency> deps = model.getDependencies(); for (Dependency dep : deps) { String scope = dep.getScope() == null ? "" : ":" + dep.getScope(); org.jboss.forge.project.dependencies.Dependency dependency = DependencyBuilder .create(dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion() + scope); if (!maven.hasDependency(dependency)) { maven.addDependency(dependency); } } } catch (IOException e) { e.printStackTrace(); } return null; } return data; }
From source file:org.apache.karaf.tooling.semantic.UnitHelp.java
License:Apache License
/** * Resolve maven URI into maven project. * <p>//from w w w .j a v a2s . c o m * Provides only model and artifact. */ public static MavenProject newProject(String mavenURI) throws Exception { final Artifact artifact = newArtifact(mavenURI); final File input = artifact.getFile(); final ModelReader reader = new DefaultModelReader(); final Model model = reader.read(input, null); final MavenProject project = new MavenProject(model); project.setArtifact(RepositoryUtils.toArtifact(artifact)); return project; }
From source file:org.eclipse.scada.build.helper.ChangeManager.java
License:Open Source License
public ChangeManager(final Log log) { this.log = log; this.writer = new DefaultModelWriter(); this.reader = new DefaultModelReader(); }
From source file:org.jenkins.ci.backend.plugin_report_card.MavenUtils.java
License:Open Source License
public static Model getModel(final URL url) { if (url != null) { InputStream inputStream = null; try {// www. j av a2 s . c o m inputStream = url.openStream(); return new DefaultModelReader().read(inputStream, MAVEN_MODEL_OPTIONS); } catch (final IOException e) { // fall through } finally { IOUtils.closeQuietly(inputStream); } } return null; }
From source file:org.sonatype.nexus.maven.staging.it.StagingMavenPluginITSupport.java
License:Open Source License
/** * Creates a project, filters if needed and prepares a Verifier to run against it. *///from www .ja v a2s. co m private PreparedVerifier createMavenVerifier(final String testId, final String mavenVersion, final File mavenSettings, final File baseDir, final String groupId, final String artifactId, final String version) throws VerificationException, IOException { final File mavenHome = mavenHomes.get(mavenVersion); if (mavenHome == null || !mavenHome.isDirectory()) { throw new IllegalArgumentException("Maven version " + mavenVersion + " was not prepared!"); } final String logNameTemplate = testId + "-maven-" + mavenVersion + "-%s.log"; final String localRepoName = "target/maven-local-repository/"; final File localRepoFile = new File(getBasedir(), localRepoName); final File filteredSettings = new File(getBasedir(), "target/settings.xml"); tasks().copy().file(file(mavenSettings)).filterUsing("nexus.port", String.valueOf(nexus().getPort())).to() .file(file(filteredSettings)).run(); final String projectGroupId; final String projectArtifactId; final String projectVersion; // filter the POM if needed final File pom = new File(baseDir, "pom.xml"); final File rawPom = new File(baseDir, "raw-pom.xml"); if (rawPom.isFile()) { projectGroupId = groupId; projectArtifactId = artifactId; projectVersion = version; final Properties context = new Properties(); context.setProperty("nexus.port", String.valueOf(nexus().getPort())); context.setProperty("itproject.groupId", projectGroupId); context.setProperty("itproject.artifactId", projectArtifactId); context.setProperty("itproject.version", projectVersion); filterPomsIfNeeded(baseDir, context); } else { // TODO: improve this, as this below is not quite true, // but this will do it for now and we do not use non-interpolated POMs for now anyway final Model model = new DefaultModelReader().read(pom, null); projectGroupId = model.getGroupId(); projectArtifactId = model.getArtifactId(); projectVersion = model.getVersion(); } System.setProperty("maven.home", mavenHome.getAbsolutePath()); final PreparedVerifier verifier = new PreparedVerifier(baseDir, projectGroupId, projectArtifactId, projectVersion, logNameTemplate) { @Override @SuppressWarnings("rawtypes") public void executeGoals(final List goals) throws VerificationException { try { super.executeGoals(goals); } finally { final File mavenLog = new File(baseDir, getLogFileName()); testIndex().recordAndCopyLink("maven.log/" + getNumberOfRuns(), mavenLog); } } }; verifier.setAutoclean(false); // no autoclean to be able to simulate multiple invocations verifier.setLocalRepo(localRepoFile.getAbsolutePath()); verifier.setMavenDebug(true); verifier.resetStreams(); List<String> options = new ArrayList<String>(); // options.add( "-X" ); options.add("-Djava.awt.headless=true"); // on Mac+OracleJdk7 a Dock icon bumps on ever Verifier invocation options.add("-Dmaven.repo.local=" + localRepoFile.getAbsolutePath()); options.add("-s " + filteredSettings.getAbsolutePath()); verifier.setCliOptions(options); return verifier; }
From source file:org.sourcepit.b2.internal.generator.AbstractPomGenerator.java
License:Apache License
protected Model readMavenModel(File pomFile) { final Map<String, String> options = new HashMap<String, String>(); options.put(ModelReader.IS_STRICT, Boolean.FALSE.toString()); try {//from w w w .j a v a 2s.c o m return new DefaultModelReader().read(pomFile, options); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.sourcepit.b2.internal.maven.MavenB2LifecycleParticipant.java
License:Apache License
private void processAttachments(MavenProject wrapperProject, File pomFile) { final List<Artifact> attachedArtifacts = wrapperProject.getAttachedArtifacts(); if (attachedArtifacts == null) { return;/*ww w. j a va2 s . co m*/ } Xpp3Dom artifactsNode = new Xpp3Dom("artifacts"); for (Artifact artifact : attachedArtifacts) { Xpp3Dom artifactNode = new Xpp3Dom("artifact"); if (artifact.getClassifier() != null) { Xpp3Dom classifierNode = new Xpp3Dom("classifier"); classifierNode.setValue(artifact.getClassifier()); artifactNode.addChild(classifierNode); } Xpp3Dom typeNode = new Xpp3Dom("type"); typeNode.setValue(artifact.getType()); artifactNode.addChild(typeNode); Xpp3Dom fileNode = new Xpp3Dom("file"); fileNode.setValue(artifact.getFile().getAbsolutePath()); artifactNode.addChild(fileNode); artifactsNode.addChild(artifactNode); } Xpp3Dom configNode = new Xpp3Dom("configuration"); configNode.addChild(artifactsNode); PluginExecution exec = new PluginExecution(); exec.setId("b2-attach-artifatcs"); exec.setPhase("initialize"); exec.getGoals().add("attach-artifact"); exec.setConfiguration(configNode); Plugin plugin = new Plugin(); plugin.setGroupId("org.codehaus.mojo"); plugin.setArtifactId("build-helper-maven-plugin"); plugin.setVersion("1.7"); plugin.getExecutions().add(exec); plugin.setInherited(false); Build build = new Build(); build.getPlugins().add(plugin); Model model = new Model(); model.setBuild(build); final Model moduleModel; try { moduleModel = new DefaultModelReader().read(pomFile, null); } catch (IOException e) { throw new IllegalStateException(e); } new ModelTemplateMerger().merge(moduleModel, model, false, null); try { new DefaultModelWriter().write(pomFile, null, moduleModel); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.sourcepit.b2.internal.maven.MavenFileFlagsProvider.java
License:Apache License
static void collectMavenModels(final File pomFile, final Map<File, Model> fileToModelMap, final Multimap<File, File> pomToModuleDirectoryMap) { try {// w w w . ja v a2 s.co m final Map<String, String> options = new HashMap<String, String>(); options.put(ModelReader.IS_STRICT, Boolean.FALSE.toString()); final ModelReader modelReader = new DefaultModelReader(); collectMavenModels(modelReader, options, pomFile, fileToModelMap, pomToModuleDirectoryMap); } catch (IOException e) { throw pipe(e); } }