org.codehaus.plexus.util.xml.pull.XmlPullParserException Java Examples
The following examples show how to use
org.codehaus.plexus.util.xml.pull.XmlPullParserException.
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: PomChangeParentTest.java From butterfly with MIT License | 6 votes |
@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 #2
Source File: NBMNativeMWITest.java From netbeans with Apache License 2.0 | 6 votes |
@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 #3
Source File: PomAddPluginTest.java From butterfly with MIT License | 6 votes |
@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 #4
Source File: PomAddParentTest.java From butterfly with MIT License | 6 votes |
@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 File: PomRemoveDependencyTest.java From butterfly with MIT License | 6 votes |
@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 #6
Source File: PomChangeParentVersionTest.java From butterfly with MIT License | 6 votes |
@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 #7
Source File: PomChangeParentVersionTest.java From butterfly with MIT License | 6 votes |
@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 #8
Source File: PomChangeParentVersionTest.java From butterfly with MIT License | 6 votes |
@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 #9
Source File: AbstractMavenActionsProvider.java From netbeans with Apache License 2.0 | 6 votes |
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 #10
Source File: CarnotzetModuleCoordinates.java From carnotzet with Apache License 2.0 | 6 votes |
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 #11
Source File: PomAddPropertyTest.java From butterfly with MIT License | 6 votes |
@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 #12
Source File: PomRemoveManagedDependencyTest.java From butterfly with MIT License | 6 votes |
@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 #13
Source File: NBMNativeMWITest.java From netbeans with Apache License 2.0 | 6 votes |
@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 #14
Source File: PomModelTest.java From butterfly with MIT License | 6 votes |
@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 #15
Source File: PomChangeParentTest.java From butterfly with MIT License | 6 votes |
@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 File: PomDependencyExistsTest.java From butterfly with MIT License | 6 votes |
@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 #17
Source File: PomCopyManagedDependenciesTest.java From butterfly with MIT License | 6 votes |
@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 #18
Source File: PomAddModuleTest.java From butterfly with MIT License | 6 votes |
@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 #19
Source File: LibrarySuggestionModel.java From scava with Eclipse Public License 2.0 | 6 votes |
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 #20
Source File: PomAddPluginTest.java From butterfly with MIT License | 6 votes |
@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 #21
Source File: PomChangePluginTest.java From butterfly with MIT License | 6 votes |
@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 #22
Source File: PomAddParentTest.java From butterfly with MIT License | 6 votes |
@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 #23
Source File: LibrarySuggestionModel.java From scava with Eclipse Public License 2.0 | 6 votes |
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 #24
Source File: PomChangeDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void defaultNotPresentTest() throws IOException, XmlPullParserException { PomChangeDependency uut = new PomChangeDependency("com.paypal", "not-present").relative("pom.xml"); TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertNotNull(executionResult.getException()); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertNotChangedFile("pom.xml"); }
Example #25
Source File: ExtensionTest.java From butterfly with MIT License | 5 votes |
@Test public void rootPomFileTest() throws URISyntaxException, IOException, XmlPullParserException { Extension extension = new SampleExtension(); Model rootPomFile = extension.getRootPomFile(new File(getClass().getResource("/sample_pom_files/goodPom").toURI())); assertNotNull(rootPomFile); assertEquals(rootPomFile.getGroupId(), "com.test.123"); assertEquals(rootPomFile.getArtifactId(), "test123"); assertEquals(rootPomFile.getVersion(), "1.0.0"); assertEquals(rootPomFile.getPackaging(), "pom"); assertEquals(rootPomFile.getName(), "test application"); }
Example #26
Source File: PomRemoveDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void defaultNotPresentTest() throws IOException, XmlPullParserException { PomRemoveDependency uut = new PomRemoveDependency("com.test", "not-present").relative("pom.xml"); assertNull(getDependencyBeforeChange(uut)); TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertExceptionOccurred(executionResult); assertNotChangedFile("pom.xml"); }
Example #27
Source File: PomRemoveDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void noOpNotPresentTest() throws IOException, XmlPullParserException { PomRemoveDependency uut = new PomRemoveDependency("com.test", "not-present").relative("pom.xml").noOpIfNotPresent(); assertNull(getDependencyBeforeChange(uut)); TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.NO_OP); assertNull(executionResult.getException()); assertEquals(executionResult.getDetails(), DEPENDENCY_NOT_REMOVED_MSG); assertNotChangedFile("pom.xml"); }
Example #28
Source File: MavenNbModuleImpl.java From netbeans with Apache License 2.0 | 5 votes |
private Xpp3Dom getModuleDom() throws UnsupportedEncodingException, IOException, XmlPullParserException { //TODO convert to FileOBject and have the IO stream from there.. File file = getModuleXmlLocation(); if (!file.exists()) { return null; } FileInputStream is = new FileInputStream(file); Reader reader = new InputStreamReader(is, "UTF-8"); //NOI18N try { return Xpp3DomBuilder.build(reader); } finally { IOUtil.close(reader); } }
Example #29
Source File: PomChangeDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void removeOptionalTest() throws IOException, XmlPullParserException { PomChangeDependency uut = new PomChangeDependency("commons-io", "commons-io").relative("pom.xml").removeOptional(); assertTrue(getDependencyBeforeChange(uut).isOptional()); executeAndAssertSuccess(uut); assertFalse(getDependencyAfterChange(uut).isOptional()); }
Example #30
Source File: PomAddManagedDependencyTest.java From butterfly with MIT License | 5 votes |
@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"); }