org.apache.maven.model.io.xpp3.MavenXpp3Reader Java Examples

The following examples show how to use org.apache.maven.model.io.xpp3.MavenXpp3Reader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CarnotzetModuleCoordinates.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
public static CarnotzetModuleCoordinates fromPom(@NonNull Path pom) {
	Model result;
	try {
		BufferedReader in = new BufferedReader(Files.newBufferedReader(pom, StandardCharsets.UTF_8));
		MavenXpp3Reader reader = new MavenXpp3Reader();
		result = reader.read(in);
	}
	catch (XmlPullParserException | IOException e) {
		throw new CarnotzetDefinitionException(e);
	}
	String groupId = result.getGroupId();
	String version = result.getVersion();
	if (groupId == null) {
		groupId = result.getParent().getGroupId();
	}
	if (version == null) {
		version = result.getParent().getVersion();
	}
	return new CarnotzetModuleCoordinates(groupId, result.getArtifactId(), version, null);
}
 
Example #2
Source File: PomReader.java    From spring-cloud-release with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a parsed POM.
 * @param pom location to the pom
 * @return parsed model
 */
public static Model readPom(File pom) {
	if (!pom.exists()) {
		throw new IllegalStateException(
				"File [" + pom.getAbsolutePath() + "] not found");
	}
	String fileText = "";
	try (Reader reader = new FileReader(pom)) {
		if (pom.isFile()) {
			fileText = new String(Files.readAllBytes(pom.toPath()));
		}
		MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
		return xpp3Reader.read(reader);
	}
	catch (XmlPullParserException | IOException e) {
		if (pom.isFile() && fileText.length() == 0) {
			throw new IllegalStateException(
					"File [" + pom.getAbsolutePath() + "] is empty", e);
		}
		throw new IllegalStateException(
				"Failed to read file: " + pom.getAbsolutePath(), e);
	}
}
 
Example #3
Source File: NBMNativeMWITest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Test
public void testPathNoParent() throws IOException, XmlPullParserException {
    clearWorkDir();
    wd = FileUtil.toFileObject(getWorkDir());
    FileObject createData = wd.createFolder("test1");
    ProjectInfo pi = new ProjectInfo("my.groupid", "artefact1", "1.0", "my.packagename");
    NBMNativeMWI.instantiate(pi, FileUtil.toFile(createData), "RELEASE110", true, null);

    FileObject builtpom = createData.getFileObject("pom", "xml");
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));

    assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
    assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
    assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
    assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
    assertEquals(0, model.getRepositories().size());
}
 
Example #4
Source File: NBMNativeMWITest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Test
public void testPathNoParentSnapshot() throws IOException, XmlPullParserException {
    clearWorkDir();
    wd = FileUtil.toFileObject(getWorkDir());
    FileObject createData = wd.createFolder("test1");
    ProjectInfo pi = new ProjectInfo("my.groupid", "artefact1", "1.0", "my.packagename");
    NBMNativeMWI.instantiate(pi, FileUtil.toFile(createData), "dev-SNAPSHOT", true, null);
    FileObject builtpom = createData.getFileObject("pom", "xml");

    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));
    assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
    assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
    assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
    assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
    assertEquals(1, model.getRepositories().size());
}
 
Example #5
Source File: PomGeneratorTest.java    From raptor with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteTo() throws IOException, XmlPullParserException {
    String artifactId = "artifactId";
    String version = "version";
    String groupId = "groupId";

    PomModel pomModel = PomModel.builder().artifactId(artifactId).groupId(groupId).version(version).build();
    PomGenerator pomGenerator = new PomGenerator(pomModel);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    pomGenerator.writeTo(baos);
    String s = baos.toString();

    MavenXpp3Reader mavenXpp3Reader = new MavenXpp3Reader();
    InputStream is = new ByteArrayInputStream(s.getBytes());

    Model generated = mavenXpp3Reader.read(is);

    Assert.assertEquals(artifactId,generated.getArtifactId());
    Assert.assertEquals(version,generated.getVersion());
    Assert.assertEquals(groupId,generated.getGroupId());

}
 
Example #6
Source File: MavenProjectWrapper.java    From gradle-plugins with MIT License 6 votes vote down vote up
public MavenProjectWrapper(Project project, File pomFile) throws IOException, XmlPullParserException {
    this.project = project;
    this.pomFile = pomFile;

    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new FileReader(pomFile));

    setModel(model);

    getBuild().setDirectory(project.getBuildDir().getAbsolutePath());

    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();

    SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    getBuild().setSourceDirectory(main.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setOutputDirectory(main.getJava().getOutputDir().getAbsolutePath());

    SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    getBuild().setTestSourceDirectory(test.getJava().getSrcDirs().iterator().next().getAbsolutePath());
    getBuild().setTestOutputDirectory(test.getJava().getOutputDir().getAbsolutePath());

    setArtifact(new ProjectArtifact(this));
}
 
Example #7
Source File: Context.java    From NoraUi with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * statisticsProcessor retrieves specific information from the robot to return it to users statistic feature.
 * 
 * @param loader
 *            is class loader.
 * @param packageName
 *            read for users statistic feature.
 * @return it to users statistic feature.
 */
protected Statistics statisticsProcessor(ClassLoader loader, String packageName) {
    Statistics stat = new Statistics();
    MavenXpp3Reader reader = new MavenXpp3Reader();
    org.apache.maven.model.Model model;
    try {
        model = reader.read(new FileReader("pom.xml"));
        stat.setNorauiVersion(model.getProperties().getProperty("noraui.version"));
        stat.setName(model.getName());
        stat.setGroupId(model.getGroupId());
        stat.setArtifactId(model.getArtifactId());
        stat.setVersion(model.getVersion());
    } catch (IOException | XmlPullParserException e) {
        log.trace("noraui.version not found.");
    }
    stat.setApplications(applications.entrySet().stream().filter(e -> e.getValue().getHomeUrl() != null).collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getHomeUrl(), (a, b) -> b)));
    try {
        Map<String, String> code = ClassPath.from(loader).getTopLevelClassesRecursive(packageName).stream().collect(Collectors.toMap(ClassInfo::getName, c -> read(c.getName()), (a, b) -> b));
        stat.setCucumberMethods(code);
    } catch (IOException e1) {
        log.trace("Cucumber Methods not found.");
    }
    return stat;
}
 
Example #8
Source File: LibrarySuggestionModel.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public void installPickedLibraries() throws FileNotFoundException, IOException, XmlPullParserException {
	MavenXpp3Reader reader = new MavenXpp3Reader();
	org.apache.maven.model.Model model = reader.read(new FileReader(pomLocation));

	pickedLibraries.forEach(library -> {
		Dependency dependency = new Dependency();
		dependency.setGroupId(library.getGroupId());
		dependency.setArtifactId(library.getArtifactId());
		dependency.setVersion(library.getVersion());

		model.addDependency(dependency);
	});

	MavenXpp3Writer writer = new MavenXpp3Writer();
	writer.write(new FileWriter(pomLocation), model);
}
 
Example #9
Source File: LibrarySuggestionModel.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private Collection<Library> readUsedLibrariesFromProject() {
	Collection<Library> usedLibraries;

	try {
		MavenXpp3Reader reader = new MavenXpp3Reader();
		org.apache.maven.model.Model model = reader.read(new FileReader(pomLocation));
		List<Dependency> dependencies = model.getDependencies();

		usedLibraries = dependencies.stream()
				.map(dependency -> new Library(Optional.ofNullable(dependency.getGroupId()).orElse(""),
						Optional.ofNullable(dependency.getArtifactId()).orElse(""),
						Optional.ofNullable(dependency.getVersion()).orElse(""), null))
				.collect(Collectors.toList());

	} catch (IOException | XmlPullParserException e1) {
		usedLibraries = new ArrayList<>();
	}

	return usedLibraries;
}
 
Example #10
Source File: AbstractDaemonGeneratorTest.java    From appassembler with MIT License 6 votes vote down vote up
private static String getAppAssemblerBooterVersion()
    throws IOException, XmlPullParserException
{
    if ( appassemblerVersion == null )
    {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        FileReader fileReader = new FileReader( getTestFile( "pom.xml" ) );
        try
        {
            appassemblerVersion = reader.read( fileReader ).getParent().getVersion();
        }
        finally
        {
            IOUtil.close( fileReader );
        }
    }
    return appassemblerVersion;
}
 
Example #11
Source File: TestEnvironmentUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static String getMavenPropertyVersionFor(String key) {
  // Maven compile uses a jar, and is in target
  String basePath = Paths.get("").toAbsolutePath().toString();
  if (basePath.endsWith("target")) {
    basePath = basePath.replace("target/", "");
  }

  String pomfile = basePath + "/../../pom.xml";
  Model model = null;
  MavenXpp3Reader mavenreader = new MavenXpp3Reader();
  try {
    FileReader reader = new FileReader(pomfile);
    model = mavenreader.read(reader);
    model.setPomFile(new File(pomfile));
  } catch (Exception ex) {
    throw new IllegalStateException("Can't find the pom.xml file. basePath=" + basePath + " pomFile=" + pomfile);
  }

  MavenProject project = new MavenProject(model);
  Properties properties = project.getProperties();
  String value = (String) properties.get(key);
  return value;
}
 
Example #12
Source File: AbstractSundrioMojo.java    From sundrio with Apache License 2.0 6 votes vote down vote up
MavenProject readProject(File pomFile) throws IOException {
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    FileReader fileReader = null;
    try {
        fileReader = new FileReader(pomFile);
        Model model = mavenReader.read(fileReader);
        model.setPomFile(pomFile);
        MavenProject project = new MavenProject(model);
        project.setFile(pomFile);
        project.setArtifact(createArtifact(pomFile, model.getGroupId(), model.getArtifactId(), model.getVersion(), "compile", model.getPackaging(), ""));
        return project;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (fileReader != null) {
            fileReader.close();
        }
    }
}
 
Example #13
Source File: InitializrSpringCloudInfoServiceTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void getSpringCloudReleaseVersionTest() throws Exception {
	String bomVersion = "vHoxton.BUILD-SNAPSHOT";
	RestTemplate rest = mock(RestTemplate.class);
	Github github = mock(Github.class);
	GithubPomReader githubPomReader = mock(GithubPomReader.class);
	when(githubPomReader.readPomFromUrl(eq(String
			.format(SpringCloudRelease.SPRING_CLOUD_STARTER_PARENT_RAW, bomVersion))))
					.thenReturn(new MavenXpp3Reader()
							.read(new FileReader(new ClassPathResource(
									"spring-cloud-starter-parent-pom.xml")
											.getFile())));
	when(githubPomReader.readPomFromUrl(eq(String.format(
			SpringCloudRelease.SPRING_CLOUD_RELEASE_DEPENDENCIES_RAW, bomVersion))))
					.thenReturn(new MavenXpp3Reader().read(new FileReader(
							new ClassPathResource("spring-cloud-dependencies-pom.xml")
									.getFile())));
	InitializrSpringCloudInfoService service = spy(
			new InitializrSpringCloudInfoService(rest, github, githubPomReader));
	doReturn(Arrays.asList(new String[] { bomVersion })).when(service)
			.getSpringCloudVersions();
	Map<String, String> releaseVersionsResult = service
			.getReleaseVersions(bomVersion);
	assertThat(releaseVersionsResult,
			Matchers.equalTo(SpringCloudInfoTestData.releaseVersions));
}
 
Example #14
Source File: InitializrSpringCloudInfoServiceTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test(expected = SpringCloudVersionNotFoundException.class)
public void getSpringCloudReleaseVersionNotFoundTest() throws Exception {
	String bomVersion = "vFooBar.BUILD-SNAPSHOT";
	RestTemplate rest = mock(RestTemplate.class);
	Github github = mock(Github.class);
	GithubPomReader githubPomReader = mock(GithubPomReader.class);
	when(githubPomReader.readPomFromUrl(eq(String
			.format(SpringCloudRelease.SPRING_CLOUD_STARTER_PARENT_RAW, bomVersion))))
					.thenReturn(new MavenXpp3Reader()
							.read(new FileReader(new ClassPathResource(
									"spring-cloud-starter-parent-pom.xml")
											.getFile())));
	when(githubPomReader.readPomFromUrl(eq(String.format(
			SpringCloudRelease.SPRING_CLOUD_RELEASE_DEPENDENCIES_RAW, bomVersion))))
					.thenReturn(new MavenXpp3Reader().read(new FileReader(
							new ClassPathResource("spring-cloud-dependencies-pom.xml")
									.getFile())));
	InitializrSpringCloudInfoService service = spy(
			new InitializrSpringCloudInfoService(rest, github, githubPomReader));
	doReturn(new ArrayList()).when(service).getSpringCloudVersions();
	service.getReleaseVersions(bomVersion);
}
 
Example #15
Source File: Verify.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
public static void verifySetupWithVersion(File pomFile) throws Exception {
    MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
    Model model = xpp3Reader.read(new FileInputStream(pomFile));

    MavenProject project = new MavenProject(model);
    Properties projectProps = project.getProperties();
    Assert.assertNotNull(projectProps);
    assertFalse(projectProps.isEmpty());
    assertEquals(projectProps.getProperty("vertx.projectVersion"),"3.4.0");
}
 
Example #16
Source File: MavenRepositoryDeployer.java    From maven-repository-tools with Eclipse Public License 1.0 5 votes vote down vote up
public static Gav getCoordinates ( File pomFile ) throws Exception
{
    BufferedReader in = new BufferedReader( new FileReader( pomFile ) );
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read( in );
    // get coordinates and take care of inheritance and default
    String g = model.getGroupId();
    if ( StringUtils.isEmpty( g ) ) 
    {
        g = model.getParent().getGroupId();
    }
    String a = model.getArtifactId();
    if ( StringUtils.isEmpty( a ) ) 
    {
        a = model.getParent().getArtifactId();
    }
    String v = model.getVersion();
    if ( StringUtils.isEmpty( v ) ) 
    {
        v = model.getParent().getVersion();
    }
    String p = model.getPackaging();
    if ( StringUtils.isEmpty( p ) ) 
    {
        p = MavenConstants.JAR;
    }
    Gav gav = new Gav( g, a, v, p );
    return gav;
}
 
Example #17
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the raw model before any interpolation what-so-ever.
 *
 * @param moduleProjectFile The project file to get the raw model for.
 * @return The raw model.
 * @throws IOException if the file is not found or if the file does not parse.
 */
public static Model getRawModel( File moduleProjectFile )
    throws IOException
{
    try (FileInputStream input = new FileInputStream( moduleProjectFile ))
    {
        return new MavenXpp3Reader().read( input );
    }
    catch ( XmlPullParserException e )
    {
        throw new IOException( e.getMessage(), e );
    }
}
 
Example #18
Source File: DeployUtil.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private static Pair<File, File> getJobJarFiles() {
    String version;
    try {
        MavenXpp3Reader pomReader = new MavenXpp3Reader();
        Model model = pomReader.read(new FileReader("../pom.xml"));
        version = model.getVersion();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    File jobJar = new File("../job/target", "kylin-job-" + version + "-job.jar");
    File coprocessorJar = new File("../storage/target", "kylin-storage-" + version + "-coprocessor.jar");
    return new Pair<File, File>(jobJar, coprocessorJar);
}
 
Example #19
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static MavenProject getMavenProject(File file) throws IOException, XmlPullParserException  {
	MavenXpp3Reader mavenXpp3Reader = new MavenXpp3Reader();
	Model model;
	final FileInputStream stream = new FileInputStream(file);
	model = mavenXpp3Reader.read(stream);
	try {
		if (stream != null) {
			stream.close();
		}
	} catch (IOException e) {
		// ignore, stream is already closed
	}
	return new MavenProject(model);
}
 
Example #20
Source File: AddMavenDependency.java    From ogham with Apache License 2.0 5 votes vote down vote up
private Model read(Project<?> project) throws AddDependencyException {
	try(FileReader fileReader = new FileReader(project.getPath().resolve("pom.xml").toFile())) {
		MavenXpp3Reader reader = new MavenXpp3Reader();
		return reader.read(fileReader);
	} catch (IOException | XmlPullParserException e) {
		throw new AddDependencyException("Failed to read pom.xml", e);
	}
}
 
Example #21
Source File: PomHelperTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroupIdNotOnChildPom()
        throws Exception
{
    URL url = getClass().getResource( "PomHelperTest.noGroupIdOnChild.pom.xml" );
    StringBuilder input = PomHelper.readXmlFile( new File( url.getPath() ) );
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read(new StringReader(input.toString()));

    assertEquals("org.myorg", PomHelper.getGroupId(model));
}
 
Example #22
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the current raw model before any interpolation what-so-ever.
 *
 * @param modifiedPomXMLEventReader The {@link ModifiedPomXMLEventReader} to get the raw model for.
 * @return The raw model.
 * @throws IOException if the file is not found or if the file does not parse.
 */
public static Model getRawModel( ModifiedPomXMLEventReader modifiedPomXMLEventReader )
    throws IOException
{
    try (StringReader stringReader = new StringReader( modifiedPomXMLEventReader.asStringBuilder().toString() ))
    {
        return new MavenXpp3Reader().read( stringReader );
    }
    catch ( XmlPullParserException e )
    {
        throw new IOException( e.getMessage(), e );
    }
}
 
Example #23
Source File: DeployUtil.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static String getPomVersion() {
    try {
        MavenXpp3Reader pomReader = new MavenXpp3Reader();
        Model model = pomReader
                .read(new InputStreamReader(new FileInputStream("../pom.xml"), StandardCharsets.UTF_8));
        return model.getVersion();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
Example #24
Source File: BomDocumentation.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@TaskAction
public void generateBomDocumentation() throws IOException, XmlPullParserException {
	MavenXpp3Reader reader = new MavenXpp3Reader();
	Model model = reader.read(new FileReader(inputFile.getAsFile().get()));



	try (PrintWriter writer = ResourceGroovyMethods.newPrintWriter(getOutputFile().getAsFile().get(), "UTF-8")) {

		writer.println("|===");
		writer.println("|Group ID |Artifact ID |Version");

		model.getDependencyManagement()
				.getDependencies()
				.stream()
				.sorted(Comparator.comparing(Dependency::getGroupId).thenComparing(Dependency::getArtifactId))
				.forEach(dependency -> {

					writer.println();
					writer.printf("|`%s`\n", dependency.getGroupId());
					writer.printf("|`%s`\n", dependency.getArtifactId());
					writer.printf("|%s\n", dependency.getVersion());
				});

		writer.println("|===");
	}

}
 
Example #25
Source File: ExtraManifestInfoTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Model buildModel(File pomFile) {
    try {
        return new MavenXpp3Reader().read(ReaderFactory.newXmlReader(pomFile));
    } catch (IOException var3) {
        throw new RuntimeException("Failed to read POM file: " + pomFile, var3);
    } catch (XmlPullParserException var4) {
        throw new RuntimeException("Failed to parse POM file: " + pomFile, var4);
    }
}
 
Example #26
Source File: TestPlugin.java    From minikube-build-tools-for-java with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws IOException, XmlPullParserException, VerificationException {
  // Installs the plugin for use in tests.
  Verifier verifier = new Verifier(".", true);
  verifier.setAutoclean(false);
  verifier.addCliOption("-DskipTests");
  verifier.executeGoal("install");

  // Reads the project version.
  MavenXpp3Reader reader = new MavenXpp3Reader();
  Model model = reader.read(new FileReader("pom.xml"));
  pluginVersion = model.getVersion();
}
 
Example #27
Source File: LicenseFinder.java    From sonarqube-licensecheck with Apache License 2.0 5 votes vote down vote up
public static List<License> getLicenses(File filePath, String userSettings, String globalSettings)
{
    try
    {
        Model model = new MavenXpp3Reader().read(new FileInputStream(filePath));

        if (!model.getLicenses().isEmpty())
        {
            return model.getLicenses();
        }
        else
        {
            if (model.getParent() != null)
            {
                Parent parent = model.getParent();
                Dependency dependency =
                    new Dependency(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion(), null);
                return getLicenses(DirectoryFinder.getPomPath(dependency,
                    DirectoryFinder.getMavenRepsitoryDir(userSettings, globalSettings)),
                    userSettings, globalSettings);
            }
            else
            {
                return Collections.emptyList();
            }
        }

    }
    catch (Exception e)
    {
        LOGGER.warn("Could not parse Maven POM " + filePath, e);
        return Collections.emptyList();
    }
}
 
Example #28
Source File: BuildManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void rewritePOM(File pomFile) throws BuildException {
	try (Reader reader = new FileReader(pomFile)) {
		MavenXpp3Reader pomReader = new MavenXpp3Reader();
		
		Model model = pomReader.read(reader);
		reader.close();
		
		model.addRepository(createRepo("maven_central", "http://repo.maven.apache.org/maven2/", "default"));
		
		for (String id: eclipseRepos.keySet()) {
			model.addRepository(createRepo(id, eclipseRepos.get(id), "p2"));
		}
		
		Build modelBuild = model.getBuild();
		if (modelBuild == null) {
			model.setBuild(new Build());
		}
		
		model.getBuild().addPlugin(createPlugin("org.eclipse.tycho", "tycho-maven-plugin", "0.21.0", true));
		model.getBuild().addPlugin(createPlugin("org.eclipse.tycho", "target-platform-configuration", "0.21.0", false));
		model.getBuild().addPlugin(createPlugin("org.apache.maven.plugins", "maven-dependency-plugin", "2.8", false));
		
		MavenXpp3Writer pomWriter = new MavenXpp3Writer();
		pomWriter.write(new FileWriter(pomFile), model);
	} 
	catch (Exception e) {
		throw new BuildException("POM rewriting (to add plugin dependencies, cause) failed unexpectedly", e);
	}
}
 
Example #29
Source File: Application.java    From Mastering-Spring-Cloud with MIT License 5 votes vote down vote up
@Bean
public Docket api() throws IOException, XmlPullParserException {
	MavenXpp3Reader reader = new MavenXpp3Reader();
	Model model = reader.read(new FileReader("pom.xml"));
	ApiInfoBuilder builder = new ApiInfoBuilder()
			.title("Person Service Api Documentation")
			.description("Documentation automatically generated")
			.version(model.getVersion())
			.contact(new Contact("Piotr MiƄkowski", "piotrminkowski.wordpress.com", "[email protected]"));
	return new Docket(DocumentationType.SWAGGER_2).select()
			.apis(RequestHandlerSelectors.basePackage("pl.piomin.services.boot.controller"))
			.paths(PathSelectors.any()).build()
			.apiInfo(builder.build());
}
 
Example #30
Source File: MavenUtilTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private MavenProject loadMavenProjectFromPom() throws IOException, XmlPullParserException {
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    File pomfile = new File(getClass().getResource("/util/test-pom.xml").getFile());
    final FileReader reader = new FileReader(pomfile);
    final Model model  = mavenreader.read(reader);
    model.setPomFile(pomfile);
    model.getBuild().setOutputDirectory(temporaryFolder.newFolder("outputDirectory").getAbsolutePath());
    model.getBuild().setDirectory(temporaryFolder.newFolder("build").getAbsolutePath());
    return new MavenProject(model);
}