Java Code Examples for org.codehaus.plexus.util.xml.pull.XmlPullParserException

The following examples show how to use org.codehaus.plexus.util.xml.pull.XmlPullParserException. These examples are extracted from open source projects. 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 Project: carnotzet   Source File: CarnotzetModuleCoordinates.java    License: 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 Project: butterfly   Source File: PomAddPluginTest.java    License: MIT License 6 votes vote down vote up
@Test
public void addPluginWithVersionTest() throws IOException, XmlPullParserException {
	Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 3);
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
	assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

       PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin", "2.10.4").relative("pom.xml");
	TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext);
	assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);

	Model pomModelAfterChange = getTransformedPomModel("pom.xml");
	assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 4);
       Plugin plugin = new Plugin();
       plugin.setGroupId("org.apache.maven.plugins");
       plugin.setArtifactId("maven-javadoc-plugin");
       assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin));
       assertEquals(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion(), "2.10.4");
}
 
Example 3
Source Project: netbeans   Source File: NBMNativeMWITest.java    License: 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 4
Source Project: butterfly   Source File: PomAddParentTest.java    License: MIT License 6 votes vote down vote up
@Test
public void addParentTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelBeforeChange.getParent());

    PomAddParent pomAddParent = new PomAddParent().setGroupId("com.newgroupid").setArtifactId("newartifactid").setVersion("2.0").relative("/src/main/resources/no_parent_pom.xml");

    assertEquals(pomAddParent.getGroupId(), "com.newgroupid");
    assertEquals(pomAddParent.getArtifactId(), "newartifactid");
    assertEquals(pomAddParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomAddParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
    assertEquals(pomAddParent.getDescription(), "Add parent artifact com.newgroupid:newartifactid in POM file /src/main/resources/no_parent_pom.xml");
    assertEquals(executionResult.getDetails(), "Parent for POM file /src/main/resources/no_parent_pom.xml has been set to com.newgroupid:newartifactid:pom:2.0");
    assertNull(executionResult.getException());

    Model pomModelAfterChange = getTransformedPomModel("/src/main/resources/no_parent_pom.xml");
    assertEquals(pomModelAfterChange.getParent().getGroupId(), "com.newgroupid");
    assertEquals(pomModelAfterChange.getParent().getArtifactId(), "newartifactid");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0");

    // Checking indentation
    File baselineFile = new File(this.getClass().getResource("/test-app/src/main/resources/added_parent_pom.xml").getFile());
    assertTrue(Files.equal(baselineFile, new File(transformedAppFolder, "/src/main/resources/no_parent_pom.xml")), "File is not formatted properly.");
}
 
Example 5
Source Project: butterfly   Source File: PomAddPluginTest.java    License: MIT License 6 votes vote down vote up
@Test
public void defaultIfPresentTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 3);
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
    assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

    // Trying to add the same plugin
    PomAddPlugin pomAddPlugin = new PomAddPlugin().setArtifact("org.codehaus.mojo:cobertura-maven-plugin").relative("pom.xml");
    TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertNull(executionResult.getDetails());
    assertEquals(executionResult.getException().getMessage(), "Plugin org.codehaus.mojo:cobertura-maven-plugin is already present in pom.xml");

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 3);
    assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 3);
    assertEquals(pomModelAfterChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo");
    assertEquals(pomModelAfterChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin");

    assertNotChangedFile("pom.xml");
}
 
Example 6
Source Project: netbeans   Source File: NBMNativeMWITest.java    License: 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 7
Source Project: butterfly   Source File: PomModelTest.java    License: MIT License 6 votes vote down vote up
@Test
public void fetchModelFromLocalTest() throws IOException, XmlPullParserException {
    Model originalPomModel = getOriginalPomModel("pom.xml");

    PomModel pomModel = new PomModel().relative("pom.xml");
    TUExecutionResult executionResult = pomModel.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TUExecutionResult.Type.VALUE);
    Model model = (Model) executionResult.getValue();

    assertEquals(originalPomModel.getGroupId(), model.getGroupId());
    assertEquals(originalPomModel.getArtifactId(), model.getArtifactId());
    assertEquals(originalPomModel.getVersion(), model.getVersion());
    assertEquals(originalPomModel.getPackaging(), model.getPackaging());
    assertEquals(originalPomModel.getName(), model.getName());
    assertEquals(originalPomModel.getDescription(), model.getDescription());
}
 
Example 8
Source Project: butterfly   Source File: PomDependencyExistsTest.java    License: MIT License 6 votes vote down vote up
@Test
public void invalidXmlFileTest() {
    PomDependencyExists pomDependencyExists;
    TUExecutionResult executionResult;

    pomDependencyExists = new PomDependencyExists("xmlunit", "xmlunit").relative("/src/main/resources/dogs.yaml");
    Assert.assertEquals(pomDependencyExists.getDescription(), "Check if dependency 'xmlunit:xmlunit' exists in a POM file");
    Assert.assertEquals(pomDependencyExists.getGroupId(), "xmlunit");
    Assert.assertEquals(pomDependencyExists.getArtifactId(), "xmlunit");
    Assert.assertNull(pomDependencyExists.getVersion());

    executionResult = pomDependencyExists.execution(transformedAppFolder, transformationContext);
    Assert.assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR);
    Assert.assertNull(executionResult.getValue());
    Assert.assertNotNull(executionResult.getException());
    Assert.assertEquals(executionResult.getException().getClass(), TransformationUtilityException.class);
    Assert.assertEquals(executionResult.getException().getMessage(), "Exception happened when checking if POM dependency xmlunit:xmlunit exists in /src/main/resources/dogs.yaml");
    Assert.assertNotNull(executionResult.getException().getCause());
    Assert.assertEquals(executionResult.getException().getCause().getClass(), XmlPullParserException.class);
    Assert.assertEquals(executionResult.getException().getCause().getMessage(), "only whitespace content allowed before start tag and not T (position: START_DOCUMENT seen T... @1:1) ");
}
 
Example 9
Source Project: butterfly   Source File: PomCopyManagedDependenciesTest.java    License: MIT License 6 votes vote down vote up
@Test
public void copyTest() throws IOException, XmlPullParserException {
    PomCopyManagedDependencies pomCopyManagedDependencies = new PomCopyManagedDependencies().relative("pom.xml")
            .setToRelative("src/main/resources/pom_less_dependencies.xml").filter("junit:junit");

    TOExecutionResult toExecutionResult = pomCopyManagedDependencies.execution(transformedAppFolder, transformationContext);
    assertNotNull(toExecutionResult);
    assertEquals(toExecutionResult.getType(), TOExecutionResult.Type.SUCCESS);

    assertNotChangedFile("pom.xml");
    assertChangedFile("src/main/resources/pom_less_dependencies.xml");
    Model transformedPomModel = getTransformedPomModel("src/main/resources/pom_less_dependencies.xml");

    assertEquals(transformedPomModel.getDependencyManagement().getDependencies().size(), 2);

    Set<String> expectedDependencies = new TreeSet<>();
    expectedDependencies.add("org.testng:testng");
    expectedDependencies.add("commons-io:commons-io");

    Set<String> actualDependencies = new TreeSet<>();
    transformedPomModel.getDependencyManagement().getDependencies().forEach(d -> actualDependencies.add(s(d)));

    assertEquals(actualDependencies, expectedDependencies);
}
 
Example 10
Source Project: butterfly   Source File: PomAddModuleTest.java    License: MIT License 6 votes vote down vote up
@Test
    public void moduleAlreadyPresentOverwriteTest() throws IOException, SAXException, ParserConfigurationException, XmlPullParserException {
        PomAddModule pomAddModule = new PomAddModule("module1").relative("pom.xml").overwriteIfPresent();
        TOExecutionResult executionResult = pomAddModule.execution(transformedAppFolder, transformationContext);

        assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
        assertNull(executionResult.getException());
        assertEquals(executionResult.getWarnings().size(), 0);

        Model pomModelAfterChange = getTransformedPomModel("pom.xml");
        assertEquals(pomModelAfterChange.getModules().size(), 1);
        assertTrue(pomModelAfterChange.getModules().contains("module1"));

// FIXME
// Uncomment this when STAX based version of this TO is implemented
//        assertNotChangedFile("pom.xml");
    }
 
Example 11
Source Project: butterfly   Source File: PomChangePluginTest.java    License: MIT License 6 votes vote down vote up
@Test
public void changePluginDependencyTest() throws IOException, XmlPullParserException {
    final Dependency dependency = new Dependency();
    dependency.setGroupId("com.test.butterfly");
    dependency.setArtifactId("butterfly-transformation");
    dependency.setVersion("1.0.0-SNAPSHOT");
    List<Dependency> dependencyList = Arrays.asList(dependency);
    PomChangePlugin uut = new PomChangePlugin("org.maven.plugins", "maven-antrun-plugin").relative("pom.xml").setPluginDependencies(dependencyList);

    assertFalse(getPluginBeforeChange(uut).getDependencies().isEmpty());
    assertNotEquals(getPluginBeforeChange(uut).getDependencies().size(), dependencyList.size());

    executeAndAssertSuccess(uut);
    List<Dependency> dependenciesAfterPluginChange = getPluginAfterChange(uut).getDependencies();

    assertEquals(dependenciesAfterPluginChange.size(), dependencyList.size());
    assertEquals(dependenciesAfterPluginChange.get(0).getArtifactId(), dependency.getArtifactId());
    assertEquals(dependenciesAfterPluginChange.get(0).getGroupId(), dependency.getGroupId());
    assertEquals(dependenciesAfterPluginChange.get(0).getVersion(), dependency.getVersion());
}
 
Example 12
Source Project: butterfly   Source File: PomChangeParentTest.java    License: MIT License 6 votes vote down vote up
@Test
public void changeVersionTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getParent().getVersion(), "1.0");

    PomChangeParent pomChangeParent = new PomChangeParent("2.0").relative("pom.xml");

    assertNull(pomChangeParent.getGroupId());
    assertNull(pomChangeParent.getArtifactId());
    assertEquals(pomChangeParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file pom.xml");
    assertNull(executionResult.getException());

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0");
}
 
Example 13
Source Project: scava   Source File: LibrarySuggestionModel.java    License: 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 14
Source Project: scava   Source File: LibrarySuggestionModel.java    License: 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 15
Source Project: butterfly   Source File: PomChangeParentTest.java    License: MIT License 6 votes vote down vote up
@Test
public void failTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelBeforeChange.getParent());

    PomChangeParent pomChangeParent = new PomChangeParent("2.0").relative("/src/main/resources/no_parent_pom.xml");

    assertNull(pomChangeParent.getGroupId());
    assertNull(pomChangeParent.getArtifactId());
    assertEquals(pomChangeParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertEquals(pomChangeParent.getDescription(), "Change parent artifact in POM file /src/main/resources/no_parent_pom.xml");
    assertEquals(executionResult.getException().getClass(), TransformationOperationException.class);
    assertEquals(executionResult.getException().getMessage(), "Pom file /src/main/resources/no_parent_pom.xml does not have a parent");

    Model pomModelAfterChange = getTransformedPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelAfterChange.getParent());

    executionResult = pomChangeParent.clone().failIfNotPresent().execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);

    assertNotChangedFile("/src/main/resources/no_parent_pom.xml");
}
 
Example 16
Source Project: butterfly   Source File: PomRemoveManagedDependencyTest.java    License: MIT License 6 votes vote down vote up
@Test
	public void warnNotPresentTest() throws IOException, XmlPullParserException {
		PomRemoveManagedDependency uut = new PomRemoveManagedDependency("com.test", "not-present").relative("pom.xml").warnIfNotPresent();

		assertNull(getManagedDependencyBeforeChange(uut));
		TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext);
		assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING);

		assertNull(executionResult.getException());
		assertEquals(executionResult.getWarnings().get(0).getClass(), TransformationOperationException.class);
		assertEquals(executionResult.getWarnings().get(0).getMessage(), MANAGED_DEPENDENCY_NOT_REMOVED_MSG);

// FIXME
// Uncomment this when STAX based version of this TO is implemented
//        assertNotChangedFile("pom.xml");
	}
 
Example 17
Source Project: butterfly   Source File: PomAddPropertyTest.java    License: MIT License 6 votes vote down vote up
@Test
    public void propertyAlreadyPresentOverwriteTest() throws IOException, SAXException, ParserConfigurationException, XmlPullParserException {
        PomAddProperty pomAddProperty = new PomAddProperty("encoding", "bar").relative("pom.xml").overwriteIfPresent();
        TOExecutionResult executionResult = pomAddProperty.execution(transformedAppFolder, transformationContext);

        assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
        assertNull(executionResult.getException());
        assertEquals(executionResult.getWarnings().size(), 0);

        Model pomModelAfterChange = getTransformedPomModel("pom.xml");
        assertEquals(pomModelAfterChange.getProperties().size(), 1);
        assertEquals(pomModelAfterChange.getProperties().getProperty("encoding"), "bar");

// FIXME
// Uncomment this when STAX based version of this TO is implemented
//        assertNotChangedFile("pom.xml");
    }
 
Example 18
Source Project: butterfly   Source File: PomChangeParentVersionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void changeVersionTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getParent().getVersion(), "1.0");

    PomChangeParentVersion pomChangeParentVersion = new PomChangeParentVersion("2.0").relative("pom.xml");

    assertEquals(pomChangeParentVersion.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParentVersion.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS);
    assertEquals(pomChangeParentVersion.getDescription(), "Change artifact's parent version in POM file pom.xml");
    assertNull(executionResult.getException());

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0");
}
 
Example 19
Source Project: butterfly   Source File: PomChangeParentVersionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void warnTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelBeforeChange.getParent());

    PomChangeParentVersion pomChangeParentVersion = new PomChangeParentVersion().relative("/src/main/resources/no_parent_pom.xml").warnIfNotPresent();
    pomChangeParentVersion.setVersion("2.0");

    assertEquals(pomChangeParentVersion.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParentVersion.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING);
    assertEquals(pomChangeParentVersion.getDescription(), "Change artifact's parent version in POM file /src/main/resources/no_parent_pom.xml");
    assertNull(executionResult.getException());
    assertEquals(executionResult.getWarnings().size(), 1);
    assertEquals(executionResult.getWarnings().get(0).getClass(), TransformationOperationException.class);
    assertEquals(executionResult.getWarnings().get(0).getMessage(), "Pom file /src/main/resources/no_parent_pom.xml does not have a parent");

    Model pomModelAfterChange = getTransformedPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelAfterChange.getParent());

    assertNotChangedFile("/src/main/resources/no_parent_pom.xml");
}
 
Example 20
Source Project: butterfly   Source File: PomChangeParentVersionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void noParentFailTest() throws IOException, XmlPullParserException, CloneNotSupportedException {
    Model pomModelBeforeChange = getOriginalPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelBeforeChange.getParent());

    PomChangeParentVersion pomChangeParentVersion = new PomChangeParentVersion("2.0").relative("/src/main/resources/no_parent_pom.xml");

    assertEquals(pomChangeParentVersion.getVersion(), "2.0");

    TOExecutionResult executionResult = pomChangeParentVersion.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    assertEquals(pomChangeParentVersion.getDescription(), "Change artifact's parent version in POM file /src/main/resources/no_parent_pom.xml");
    assertEquals(executionResult.getException().getClass(), TransformationOperationException.class);
    assertEquals(executionResult.getException().getMessage(), "Pom file /src/main/resources/no_parent_pom.xml does not have a parent");

    Model pomModelAfterChange = getTransformedPomModel("/src/main/resources/no_parent_pom.xml");
    assertNull(pomModelAfterChange.getParent());

    executionResult = pomChangeParentVersion.clone().failIfNotPresent().execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);

    assertNotChangedFile("/src/main/resources/no_parent_pom.xml");
}
 
Example 21
Source Project: netbeans   Source File: AbstractMavenActionsProvider.java    License: Apache License 2.0 6 votes vote down vote up
private NetbeansActionMapping findMapAction(Map<String, String> replaceMap, Project project, String actionName) throws XmlPullParserException, IOException {
    // TODO need some caching really badly here..
    Reader read = performDynamicSubstitutions(replaceMap, getRawMappingsAsString());
    ActionToGoalMapping mapping = reader.read(read);
    Iterator<NetbeansActionMapping> it = mapping.getActions().iterator();
    NetbeansActionMapping action = null;
    NbMavenProject mp = project.getLookup().lookup(NbMavenProject.class);
    String prjPack = mp.getPackagingType();
    while (it.hasNext()) {
        NetbeansActionMapping elem = it.next();
        if (actionName.equals(elem.getActionName()) &&
                (elem.getPackagings().contains(prjPack.trim()) ||
                elem.getPackagings().contains("*") || elem.getPackagings().isEmpty())) {//NOI18N
            action = elem;
            break;
        }
    }
    return action;
}
 
Example 22
Source Project: butterfly   Source File: PomRemoveDependencyTest.java    License: MIT License 6 votes vote down vote up
@Test
	public void warnNotPresentTest() throws IOException, XmlPullParserException {
		PomRemoveDependency uut = new PomRemoveDependency("com.test", "not-present").relative("pom.xml").warnIfNotPresent();

		assertNull(getDependencyBeforeChange(uut));
		TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext);
		assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING);

		assertNull(executionResult.getException());
		assertEquals(executionResult.getWarnings().get(0).getClass(), TransformationOperationException.class);
		assertEquals(executionResult.getWarnings().get(0).getMessage(), DEPENDENCY_NOT_REMOVED_MSG);

// FIXME
// Uncomment this when STAX based version of this TO is implemented
//        assertNotChangedFile("pom.xml");
	}
 
Example 23
Source Project: butterfly   Source File: PomAddParentTest.java    License: MIT License 6 votes vote down vote up
@Test
public void noOpTest() throws IOException, XmlPullParserException {
    Model pomModelBeforeChange = getOriginalPomModel("pom.xml");
    assertEquals(pomModelBeforeChange.getParent().getGroupId(), "com.test");
    assertEquals(pomModelBeforeChange.getParent().getArtifactId(), "foo-parent");
    assertEquals(pomModelBeforeChange.getParent().getVersion(), "1.0");

    PomAddParent pomAddParent = new PomAddParent().setGroupId("com.newgroupid").setArtifactId("newartifactid").setVersion("2.0").relative("pom.xml").noOpIfPresent();

    assertEquals(pomAddParent.getGroupId(), "com.newgroupid");
    assertEquals(pomAddParent.getArtifactId(), "newartifactid");
    assertEquals(pomAddParent.getVersion(), "2.0");

    TOExecutionResult executionResult = pomAddParent.execution(transformedAppFolder, transformationContext);
    assertEquals(executionResult.getType(), TOExecutionResult.Type.NO_OP);
    assertEquals(pomAddParent.getDescription(), "Add parent artifact com.newgroupid:newartifactid in POM file pom.xml");
    assertNull(executionResult.getException());
    assertEquals(executionResult.getDetails(), "Pom file /pom.xml already has a parent");

    Model pomModelAfterChange = getTransformedPomModel("pom.xml");
    assertEquals(pomModelAfterChange.getParent().getGroupId(), "com.test");
    assertEquals(pomModelAfterChange.getParent().getArtifactId(), "foo-parent");
    assertEquals(pomModelAfterChange.getParent().getVersion(), "1.0");

    assertNotChangedFile("pom.xml");
}
 
Example 24
Source Project: jkube   Source File: MavenUtilTest.java    License: 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);
}
 
Example 25
Source Project: butterfly   Source File: PomAddManagedDependencyTest.java    License: MIT License 5 votes vote down vote up
@Test
public void failIfPresentTest() throws IOException, XmlPullParserException {
    PomAddManagedDependency uut = new PomAddManagedDependency("junit", "junit", "4.11").relative("pom.xml").failIfPresent();

    TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext);
    Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR);
    Assert.assertNotNull(executionResult.getException());
    Assert.assertEquals(executionResult.getException().getClass(), TransformationOperationException.class);
    Dependency dependencyAfterChange = getManagedDependencyInList(getTransformedPomModel("pom.xml"), "junit", "junit", "4.11");
    Assert.assertNull(dependencyAfterChange);

    assertNotChangedFile("pom.xml");
}
 
Example 26
Source Project: vertx-maven-plugin   Source File: MojoUtilsTest.java    License: 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 27
Source Project: butterfly   Source File: PomAddDependencyTest.java    License: MIT License 5 votes vote down vote up
@Test
public void addDependencyWithScopeTest() throws IOException, XmlPullParserException {
    PomAddDependency uut = new PomAddDependency("org.springframework.batch", "spring-batch-core", "3.0.7.RELEASE").relative("pom.xml").setScope("provided");

    Assert.assertNull(getDependencyBeforeChange(uut));
    executeAndAssertSuccess(uut);
    Dependency dependencyAfterChange = getDependencyAfterChange(uut);
    Assert.assertNotNull(dependencyAfterChange);
    Assert.assertEquals(dependencyAfterChange.getGroupId(), "org.springframework.batch");
    Assert.assertEquals(dependencyAfterChange.getArtifactId(), "spring-batch-core");
    Assert.assertEquals(dependencyAfterChange.getVersion(), "3.0.7.RELEASE");
    Assert.assertEquals(dependencyAfterChange.getScope(), "provided");

}
 
Example 28
Source Project: butterfly   Source File: PomAddDependencyTest.java    License: MIT License 5 votes vote down vote up
@Test
public void noOpIfPresentTest() throws IOException, XmlPullParserException {
    PomAddDependency uut = new PomAddDependency("xmlunit", "xmlunit", "1.7").relative("pom.xml").noOpIfPresent();

    TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext);
    Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.NO_OP);
    Assert.assertNull(executionResult.getException());
    Dependency dependencyAfterChange = getDependencyInList(getTransformedPomModel("pom.xml"), "xmlunit", "xmlunit", "1.7");
    Assert.assertNull(dependencyAfterChange);

    assertNotChangedFile("pom.xml");
}
 
Example 29
Source Project: java-specialagent   Source File: MavenUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static String getArtifactFile(final File dir) {
  try {
    final Model model = getModel(new File(dir, "pom.xml"));
    final String version = model.getVersion() != null ? model.getVersion() : model.getParent().getVersion();
    return model.getArtifactId() + "-" + version + ".jar";
  }
  catch (final IOException | XmlPullParserException e) {
    throw new IllegalStateException(e);
  }
}
 
Example 30
Source Project: butterfly   Source File: PomAddManagedDependencyTest.java    License: MIT License 5 votes vote down vote up
@Test
    public void warnNotAddIfPresentTest() throws IOException, XmlPullParserException {
        PomAddManagedDependency uut = new PomAddManagedDependency("junit", "junit", "1.7").relative("pom.xml").warnNotAddIfPresent();

        TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext);
        Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING);
        Assert.assertNull(executionResult.getException());
        Dependency dependencyAfterChange = getManagedDependencyInList(getTransformedPomModel("pom.xml"), "xmlunit", "xmlunit", "1.7");
        Assert.assertNull(dependencyAfterChange);

// FIXME
// Uncomment this when STAX based version of this TO is implemented
//        assertNotChangedFile("pom.xml");
    }