org.apache.maven.model.Model Java Examples
The following examples show how to use
org.apache.maven.model.Model.
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: ModelTree.java From butterfly with MIT License | 6 votes |
/** * This is a tree of Maven artifacts, which are represented by {@link Model} objects. * The idea here is, given a list of Maven pom.xml {@link File} objects, create a tree * based on dependency among them, but specifying explicitly which Maven artifact should * be at the root of the tree. That means, if any artifact in the list is not a child, * directly or indirectly, of the root artifact, then it will end up no being in the tree. * <br> * As a result of building this tree, it is possible to know, out of the initial pom.xml files list, * which ones actually inherit, directly or not, from the root artifact. The result is retrieved * by calling {@link #getPomFilesInTree()} * * @param rootGroupId the group id of the artifact that should be at the root of the tree * @param rootArtifactId the artifact id of the artifact that should be at the root of the tree * @param rootVersion the version of the artifact that should be at the root of the tree * @param pomFiles a list of pom.xml files used to make the tree */ public ModelTree(String rootGroupId, String rootArtifactId, String rootVersion, List<File> pomFiles) { Model rootModel = new Model(); rootModel.setGroupId(rootGroupId); rootModel.setArtifactId(rootArtifactId); rootModel.setVersion(rootVersion); List<Model> models = new ArrayList<>(); models.add(rootModel); for (File pomFile : pomFiles) { models.add(createModel(pomFile)); } // TODO we can comment this out in the future if we need this feature // modelsNotInTree = add(models); add(models); }
Example #2
Source File: MavenUtils.java From wisdom with Apache License 2.0 | 6 votes |
private static Map getProperties(Model projectModel, String prefix) { Map<String, String> properties = new LinkedHashMap<>(); Method[] methods = Model.class.getDeclaredMethods(); for (Method method : methods) { String name = method.getName(); if (name.startsWith("get")) { try { Object v = method.invoke(projectModel); if (v != null) { name = prefix + Character.toLowerCase(name.charAt(3)) + name.substring(4); if (v.getClass().isArray()) { properties.put(name, Arrays.asList((Object[]) v).toString()); } else { properties.put(name, v.toString()); } } } catch (Exception e) { //NOSONAR // too bad } } } return properties; }
Example #3
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 #4
Source File: ArtifactServerUtil.java From LicenseScout with Apache License 2.0 | 6 votes |
private boolean evaluatePomLicenses(final Archive archive, final String filePath, final LicenseStoreData licenseStoreData, final Model model) { boolean licenseFound = false; final List<org.apache.maven.model.License> licenses = model.getLicenses(); for (final org.apache.maven.model.License license : licenses) { final String licenseUrl = license.getUrl(); final String licenseName = license.getName(); log.debug("License name: " + licenseName); log.debug("License URL: " + licenseUrl); final boolean licenseFoundForUrl = LicenseUtil.handleLicenseUrl(licenseUrl, archive, filePath, licenseStoreData, log); licenseFound |= licenseFoundForUrl; boolean licenseFoundForName = false; if (!licenseFoundForUrl) { licenseFoundForName = LicenseUtil.handleLicenseName(licenseName, archive, filePath, licenseStoreData, log); licenseFound |= licenseFoundForName; } if (!licenseFoundForUrl && !licenseFoundForName) { log.warn("Neither license name nor license URL mapping found for name/URL: " + licenseName + " / " + licenseUrl); } } return licenseFound; }
Example #5
Source File: FlattenMojo.java From flatten-maven-plugin with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void execute() throws MojoExecutionException, MojoFailureException { getLog().info( "Generating flattened POM of project " + this.project.getId() + "..." ); File originalPomFile = this.project.getFile(); Model flattenedPom = createFlattenedPom( originalPomFile ); String headerComment = extractHeaderComment( originalPomFile ); File flattenedPomFile = getFlattenedPomFile(); writePom( flattenedPom, flattenedPomFile, headerComment ); if ( isUpdatePomFile() ) { this.project.setPomFile( flattenedPomFile ); } }
Example #6
Source File: SpringCloudMavenBomParser.java From spring-cloud-release-tools with Apache License 2.0 | 6 votes |
private String boot(File root, ReleaserProperties properties) { String bootVersion = properties.getFixedVersions().get(SPRING_BOOT); if (StringUtils.hasText(bootVersion)) { return bootVersion; } String pomWithBootStarterParent = properties.getPom() .getPomWithBootStarterParent(); File pom = new File(root, pomWithBootStarterParent); if (!pom.exists()) { return ""; } Model model = PomReader.pom(root, pomWithBootStarterParent); if (model == null) { return ""; } String bootArtifactId = model.getParent().getArtifactId(); log.debug("Boot artifact id is equal to [{}]", bootArtifactId); if (!BOOT_STARTER_PARENT_ARTIFACT_ID.equals(bootArtifactId)) { if (log.isDebugEnabled()) { throw new IllegalStateException("The pom doesn't have a [" + BOOT_STARTER_PARENT_ARTIFACT_ID + "] artifact id"); } return ""; } return model.getParent().getVersion(); }
Example #7
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 #8
Source File: PomAddParentTest.java From butterfly with MIT License | 6 votes |
@Test public void failTest() 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").failIfPresent(); 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.ERROR); assertEquals(pomAddParent.getDescription(), "Add parent artifact com.newgroupid:newartifactid in POM file pom.xml"); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertEquals(executionResult.getException().getMessage(), "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 #9
Source File: LocalProject.java From quarkus with Apache License 2.0 | 6 votes |
private static Model loadRootModel(Path pomXml) throws BootstrapMavenException { Model model = null; while (pomXml != null && Files.exists(pomXml)) { model = readModel(pomXml); final Parent parent = model.getParent(); if (parent != null && parent.getRelativePath() != null && !parent.getRelativePath().isEmpty()) { pomXml = pomXml.getParent().resolve(parent.getRelativePath()).normalize(); if (Files.isDirectory(pomXml)) { pomXml = pomXml.resolve(POM_XML); } } else { final Path parentDir = pomXml.getParent().getParent(); pomXml = parentDir == null ? null : parentDir.resolve(POM_XML); } } return model; }
Example #10
Source File: PomChangeParentTest.java From butterfly with MIT License | 6 votes |
@Test public void changeParentTest() 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"); PomChangeParent pomChangeParent = new PomChangeParent().setGroupId("com.newgroupid").setArtifactId("newartifactid").setVersion("2.0").relative("pom.xml"); assertEquals(pomChangeParent.getGroupId(), "com.newgroupid"); assertEquals(pomChangeParent.getArtifactId(), "newartifactid"); 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().getGroupId(), "com.newgroupid"); assertEquals(pomModelAfterChange.getParent().getArtifactId(), "newartifactid"); assertEquals(pomModelAfterChange.getParent().getVersion(), "2.0"); }
Example #11
Source File: GAVTest.java From maven-git-versioning-extension with MIT License | 6 votes |
@Test void of_model() { // Given Model model = new Model(); model.setGroupId("group"); model.setArtifactId("artifact"); model.setVersion("version"); // When GAV gav = GAV.of(model); // Then assertThat(gav).isNotNull(); assertThat(gav.getGroupId()).isEqualTo("group"); assertThat(gav.getArtifactId()).isEqualTo("artifact"); assertThat(gav.getVersion()).isEqualTo("version"); }
Example #12
Source File: CommandRequirements.java From helidon-build-tools with Apache License 2.0 | 6 votes |
/** * Require that a valid Maven project configuration exists. * * @param commonOptions The options. */ static void requireValidMavenProjectConfig(CommonOptions commonOptions) { try { Path projectDir = commonOptions.project(); Path pomFile = PomUtils.toPomFile(projectDir); Path projectConfigFile = ProjectConfig.toDotHelidon(projectDir); if (!Files.exists(projectConfigFile)) { // Find the helidon version if we can and create the config file Model model = PomUtils.readPomModel(pomFile); Parent parent = model.getParent(); String helidonVersion = null; if (parent != null && parent.getGroupId().startsWith("io.helidon.")) { helidonVersion = parent.getVersion(); } ensureProjectConfig(projectDir, helidonVersion); } } catch (IllegalArgumentException e) { String message = e.getMessage(); if (message.contains("does not exist")) { message = NOT_A_PROJECT_DIR; } Requirements.failed(message); } }
Example #13
Source File: AutoDiscoverDeployService.java From vertx-deploy-tools with Apache License 2.0 | 6 votes |
private List<Artifact> getDeployDependencies(Artifact artifact, List<Exclusion> exclusions, boolean testScope, Map<String, String> properties, DeployType type) { ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); descriptorRequest.setRepositories(AetherUtil.newRepositories(deployConfig)); descriptorRequest.setArtifact(artifact); Model model = AetherUtil.readPom(artifact); if (model == null) { throw new IllegalStateException("Unable to read POM for " + artifact.getFile()); } try { ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest); return descriptorResult.getDependencies().stream() .filter(d -> type == DeployType.DEFAULT || (type == DeployType.APPLICATION && !d.getArtifact().getExtension().equals("zip")) || (type == DeployType.ARTIFACT && !d.getArtifact().getExtension().equals("jar"))) .filter(d -> "compile".equalsIgnoreCase(d.getScope()) || ("test".equalsIgnoreCase(d.getScope()) && testScope)) .filter(d -> !exclusions.contains(new Exclusion(d.getArtifact().getGroupId(), d.getArtifact().getArtifactId(), null, null))) .map(Dependency::getArtifact) .map(d -> this.checkWithModel(model, d, properties)) .collect(Collectors.toList()); } catch (ArtifactDescriptorException e) { LOG.error("Unable to resolve dependencies for deploy artifact '{}', unable to auto-discover ", artifact, e); } return Collections.emptyList(); }
Example #14
Source File: DistributionEnforcingManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
private void applyTest( final EnforcingMode mode, final Model model, final Model expectChanged ) throws Exception { setModeProperty( mode ); setMavenSession(); manipulator.init( session ); final Project project = new Project( model ); final List<Project> projects = new ArrayList<>(); projects.add( project ); final Set<Project> changed = manipulator.applyChanges( projects ); if ( expectChanged != null ) { assertThat( changed.isEmpty(), equalTo( false ) ); assertThat( changed.contains( new Project( expectChanged ) ), equalTo( true ) ); } else { assertThat( changed.isEmpty(), equalTo( true ) ); } }
Example #15
Source File: LocalProject.java From quarkus with Apache License 2.0 | 6 votes |
public static LocalProject loadWorkspace(Path path, boolean required) throws BootstrapMavenException { path = path.normalize().toAbsolutePath(); Path currentProjectPom = null; Model rootModel = null; if (!Files.isDirectory(path)) { // see if that's an actual pom try { rootModel = loadRootModel(path); if (rootModel != null) { currentProjectPom = path; } } catch (BootstrapMavenException e) { // ignore, it's not a POM file, we'll be looking for the POM later } } if (currentProjectPom == null) { currentProjectPom = locateCurrentProjectPom(path, required); if (currentProjectPom == null) { return null; } rootModel = loadRootModel(currentProjectPom); } return loadWorkspace(currentProjectPom, rootModel); }
Example #16
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 #17
Source File: NewGraniteProjectWizard.java From aem-eclipse-developer-tools with Apache License 2.0 | 6 votes |
private void fixParentProject(IProject p, IProject parentProject) throws CoreException { IFile existingPom = p.getFile("pom.xml"); Model model = MavenPlugin.getMavenModelManager().readMavenModel(existingPom); Model parent = MavenPlugin.getMavenModelManager().readMavenModel(parentProject.getFile("pom.xml")); //Parent oldParent = model.getParent(); Parent newParent = new Parent(); newParent.setGroupId(parent.getGroupId()); newParent.setArtifactId(parent.getArtifactId()); newParent.setRelativePath(calculateRelativePath(p, parentProject)); newParent.setVersion(parent.getVersion()); model.setParent(newParent); // outright deletion doesn't work on windows as the process has a ref to the file itself // so creating a temp '_newpom_.xml' final IFile newPom = p.getFile("_newpom_.xml"); MavenPlugin.getMavenModelManager().createMavenModel(newPom, model); // then copying that content over to the pom.xml existingPom.setContents(newPom.getContents(), true, true, new NullProgressMonitor()); // and deleting the temp pom newPom.delete(true, false, new NullProgressMonitor()); }
Example #18
Source File: ModelUtils.java From quarkus with Apache License 2.0 | 5 votes |
/** * Returns the raw version of the model. If the model does not include * the version directly, it will return the version of the parent. * The version is raw in a sense if it's a property expression, the * expression will not be resolved. * * @param model POM * @return raw model */ public static String getRawVersion(Model model) { String version = model.getVersion(); if (version != null) { return version; } final Parent parent = model.getParent(); if (parent != null) { version = parent.getVersion(); if (version != null) { return version; } } throw new IllegalStateException("Failed to determine version for project model"); }
Example #19
Source File: AddExtensionMojoTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAddSingleDependency() throws MojoExecutionException, IOException, XmlPullParserException { mojo.extension = DEP_GAV; mojo.extensions = new HashSet<>(); mojo.execute(); Model reloaded = reload(); List<Dependency> dependencies = reloaded.getDependencies(); assertThat(dependencies).hasSize(1); assertThat(dependencies.get(0).getArtifactId()).isEqualTo("commons-lang3"); }
Example #20
Source File: SetupVerifier.java From quarkus with Apache License 2.0 | 5 votes |
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(); assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); final String quarkusVersion = getPlatformDescriptor().getQuarkusVersion(); assertEquals(quarkusVersion, projectProps.getProperty(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLUGIN_VERSION_NAME)); }
Example #21
Source File: WriteMavenPomStep.java From pipeline-utility-steps-plugin with MIT License | 5 votes |
@DataBoundConstructor public WriteMavenPomStep(Model model) { if (model == null) { throw new IllegalArgumentException("model must be non-null"); } this.model = model; }
Example #22
Source File: MavenUploadHandlerTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test(expected = ValidationErrorsException.class) public void testValidatePom_groupIdWithProperty() { Model model = new Model(); model.setGroupId("${aProperty}"); model.setArtifactId("testArtifact"); model.setVersion("1.0"); underTest.validatePom(model); }
Example #23
Source File: DataflowDependencyManager.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private Model getModelFromProject(IProject project) { IMavenProjectFacade facade = mavenProjectRegistry.getProject(project); if (facade != null) { IFile pom = facade.getPom(); try { return maven.readModel(pom.getContents()); } catch (CoreException e) { return null; } } return null; }
Example #24
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Returns the model that has the specified groupId and artifactId or <code>null</code> if no such model exists. * * @param reactor The map of models keyed by path. * @param groupId The groupId to match. * @param artifactId The artifactId to match. * @return The model entry or <code>null</code> if the model was not in the reactor. */ public static Map.Entry<String, Model> getModelEntry( Map<String, Model> reactor, String groupId, String artifactId ) { for ( Map.Entry<String, Model> entry : reactor.entrySet() ) { Model model = entry.getValue(); if ( groupId.equals( getGroupId( model ) ) && artifactId.equals( getArtifactId( model ) ) ) { return entry; } } return null; }
Example #25
Source File: ExtraManifestInfoTest.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
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: AbstractSetQualifierMojo.java From neoscada with Eclipse Public License 1.0 | 5 votes |
private void checkNonRelativeParent ( final MavenProject project ) { if ( project.getModel ().getParent () == null ) { // no parent return; } if ( project.getParentFile () != null ) { // is a local parent return; } final Parent parent = project.getModel ().getParent (); final String prefix = String.format ( "%s:%s:", parent.getGroupId (), parent.getArtifactId () ); for ( final String entry : this.forceUpdateParentQualifiers ) { if ( entry.startsWith ( prefix ) ) { final String qualifier = entry.substring ( prefix.length () ); final String newVersion = makeVersion ( parent.getVersion (), qualifier ); getLog ().info ( String.format ( "Force update parent of %s to %s -> %s", project.getId (), parent.getId (), newVersion ) ); addChange ( project.getFile (), new ModelModifier () { @Override public boolean apply ( final Model model ) { model.getParent ().setVersion ( newVersion ); return true; } } ); } } }
Example #27
Source File: ModelUtils.java From quarkus with Apache License 2.0 | 5 votes |
/** * If the model contains properties, this method overrides those that appear to be * defined as system properties. */ public static Model applySystemProperties(Model model) { final Properties props = model.getProperties(); for (Map.Entry<Object, Object> prop : model.getProperties().entrySet()) { final String systemValue = PropertyUtils.getProperty(prop.getKey().toString()); if (systemValue != null) { props.put(prop.getKey(), systemValue); } } return model; }
Example #28
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * 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 #29
Source File: PomRemovePropertyTest.java From butterfly with MIT License | 5 votes |
@Test public void propertyRemovedTest() throws IOException, XmlPullParserException { Model pomModelBeforeChange = getOriginalPomModel("pom.xml"); assertEquals(pomModelBeforeChange.getProperties().size(), 1); assertEquals(pomModelBeforeChange.getProperties().getProperty("encoding"), "UTF-8"); PomRemoveProperty pomRemoveProperty = new PomRemoveProperty("encoding").relative("pom.xml"); assertEquals(pomRemoveProperty.getPropertyName(), "encoding"); TOExecutionResult executionResult = pomRemoveProperty.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); Model pomModelAfterChange = getTransformedPomModel("pom.xml"); assertEquals(pomModelAfterChange.getProperties().size(), 0); }
Example #30
Source File: Application.java From Mastering-Spring-Cloud with MIT License | 5 votes |
@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()); }