Java Code Examples for org.apache.maven.project.MavenProject#getProperties()
The following examples show how to use
org.apache.maven.project.MavenProject#getProperties() .
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: MojoHelper.java From helidon-build-tools with Apache License 2.0 | 6 votes |
/** * Make a properties map to be used as a mustache scope object. * * @param properties base properties to include * @param includeProjectProperties {@code true} if project properties should be included * @param project maven project to get the project properties, {@code project.*} properties are emulated * @return Properties map */ static Map<String, String> templateProperties(Map<String, String> properties, boolean includeProjectProperties, MavenProject project) { Map<String, String> props = new HashMap<>(); props.putAll(properties); if (includeProjectProperties) { Properties projectProperties = project.getProperties(); props.putAll(Maps.fromProperties(project.getProperties())); props.put("project.groupId", project.getGroupId()); props.put("project.artifactId", project.getArtifactId()); props.put("project.version", project.getVersion()); props.put("project.name", project.getName()); props.put("project.description", project.getDescription()); } return props; }
Example 2
Source File: DevMojo.java From ci.maven with Apache License 2.0 | 6 votes |
private boolean hasServerPropertyChanged(MavenProject project, MavenProject backupProject) { Properties projProp = project.getProperties(); Properties backupProjProp = backupProject.getProperties(); if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_BOOTSTRAP_PROP), getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_BOOTSTRAP_PROP))) { return true; } if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_JVM_PROP), getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_JVM_PROP))) { return true; } if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_ENV_PROP), getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_ENV_PROP))) { return true; } return false; }
Example 3
Source File: DockerFileUtilTest.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private MojoParameters mockMojoParams() { MavenProject project = new MavenProject(); project.setArtifactId("docker-maven-plugin"); Properties projectProperties = project.getProperties(); projectProperties.put("base", "java"); projectProperties.put("name", "guenther"); projectProperties.put("age", "42"); projectProperties.put("ext", "png"); Settings settings = new Settings(); ArtifactRepository localRepository = new MavenArtifactRepository() { public String getBasedir() { return "repository"; } }; @SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date(System.currentTimeMillis())); session.getUserProperties().setProperty("cliOverride", "cliValue"); // Maven CLI override: -DcliOverride=cliValue session.getSystemProperties().put("user.name", "somebody"); // Java system property: -Duser.name=somebody return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project)); }
Example 4
Source File: TestEnvironmentUtil.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static String getMavenPropertyVersionFor(String key) { // Maven compile uses a jar, and is in target String basePath = Paths.get("").toAbsolutePath().toString(); if (basePath.endsWith("target")) { basePath = basePath.replace("target/", ""); } String pomfile = basePath + "/../../pom.xml"; Model model = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { FileReader reader = new FileReader(pomfile); model = mavenreader.read(reader); model.setPomFile(new File(pomfile)); } catch (Exception ex) { throw new IllegalStateException("Can't find the pom.xml file. basePath=" + basePath + " pomFile=" + pomfile); } MavenProject project = new MavenProject(model); Properties properties = project.getProperties(); String value = (String) properties.get(key); return value; }
Example 5
Source File: MavenProjectUtil.java From microprofile-sandbox with Apache License 2.0 | 5 votes |
public static String getJavaCompilerTargetVersion(MavenProject project) { // Check maven compiler properties Properties mavenProperties = project.getProperties(); for (Map.Entry<Object, Object> property : mavenProperties.entrySet()) { String propertyKey = property.getKey().toString(); String propertyValue = property.getValue().toString(); if (propertyKey.equals("maven.compiler.target") || propertyKey.equals("maven.compiler.release")) { return propertyValue; } } // Check maven-compiler-plugin release value String release = net.wasdev.wlp.maven.plugins.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "release"); if (release != null) { return release; } // Check maven-compiler-plugin target value String target = net.wasdev.wlp.maven.plugins.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "target"); if (target != null) { return target; } return ""; }
Example 6
Source File: DevMojo.java From ci.maven with Apache License 2.0 | 5 votes |
private boolean hasServerVariableChanged(MavenProject project, MavenProject backupProject) { Properties projProp = project.getProperties(); Properties backupProjProp = backupProject.getProperties(); if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_VAR_PROP), getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_VAR_PROP))) { return true; } if (!Objects.equals(getPropertiesWithKeyPrefix(projProp, LIBERTY_DEFAULT_VAR_PROP), getPropertiesWithKeyPrefix(backupProjProp, LIBERTY_DEFAULT_VAR_PROP))) { return true; } return false; }
Example 7
Source File: UnchangedProjectsRemover.java From gitflow-incremental-builder with MIT License | 5 votes |
private MavenProject applyUpstreamModuleArgs(MavenProject mavenProject) { final Properties projectProperties = mavenProject.getProperties(); if (configProvider.get().skipTestsForUpstreamModules) { if (projectDeclaresTestJarGoal(mavenProject)) { logger.debug("{}: {}", mavenProject.getArtifactId(), TEST_JAR_DETECTED); projectProperties.setProperty(MAVEN_TEST_SKIP_EXEC, Boolean.TRUE.toString()); } else { projectProperties.setProperty(MAVEN_TEST_SKIP, Boolean.TRUE.toString()); } } configProvider.get().argsForUpstreamModules.forEach(projectProperties::setProperty); return mavenProject; }
Example 8
Source File: MavenUtils.java From mvn-golang with Apache License 2.0 | 5 votes |
@Nullable public static String findProperty( @Nonnull final MavenSession session, @Nonnull final MavenProject project, @Nonnull final String key, @Nullable final String dflt ) { final Properties properties = new Properties(project.getProperties()); properties.putAll( session.getSystemProperties() ); properties.putAll( session.getUserProperties() ); return properties.getProperty(key, dflt); }
Example 9
Source File: Verify.java From vertx-maven-plugin 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(); Assert.assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); assertEquals(projectProps.getProperty("vertx.projectVersion"),"3.4.0"); }
Example 10
Source File: MavenProjectSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static String readSettingsFromPom(Project project, final String key) { final NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); if (nbMavenProject != null) { MavenProject mavenProject = nbMavenProject.getMavenProject(); java.util.Properties properties = mavenProject.getProperties(); if (properties != null) { return properties.getProperty(key); } } return null; }
Example 11
Source File: PluginPropertyUtils.java From netbeans with Apache License 2.0 | 5 votes |
static @NonNull ExternalDefaultBuilder<String> simpleDefaultProperty(final @NullAllowed String expressionProperty) { return new ExternalDefaultBuilder<String>() { @Override public String externalValue(MavenProject prj) { if (expressionProperty == null) { return null; } Properties prop = prj.getProperties(); if (prop != null) { return prop.getProperty(expressionProperty); } return null; } }; }
Example 12
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 13
Source File: Verify.java From vertx-maven-plugin 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()); assertEquals(projectProps.getProperty("vertx.version"), "3.4.0"); }
Example 14
Source File: MavenProjectUtil.java From boost with Eclipse Public License 1.0 | 5 votes |
public static String getJavaCompilerTargetVersion(MavenProject project) { // Check maven compiler properties Properties mavenProperties = project.getProperties(); for (Map.Entry<Object, Object> property : mavenProperties.entrySet()) { String propertyKey = property.getKey().toString(); String propertyValue = property.getValue().toString(); if (propertyKey.equals("maven.compiler.target") || propertyKey.equals("maven.compiler.release")) { return propertyValue; } } // Check maven-compiler-plugin release value String release = io.openliberty.tools.maven.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "release"); if (release != null) { return release; } // Check maven-compiler-plugin target value String target = io.openliberty.tools.maven.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "target"); if (target != null) { return target; } return ""; }
Example 15
Source File: SetupMojoTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testVerticleCreatPom() throws Exception { new File("target/unit/nopom").mkdirs(); File pomFile = new File("target/unit/nopom/pom.xml"); String vertxVersion = MojoUtils.getVersion("vertx-core-version"); Map<String, String> tplContext = new HashMap<>(); tplContext.put("mProjectGroupId", "com.example.vertx"); tplContext.put("mProjectArtifactId", "vertx-example"); tplContext.put("mProjectVersion", "1.0-SNAPSHOT"); tplContext.put("vertxVersion", vertxVersion); tplContext.put("vertxVerticle", "com.example.vertx.MainVerticle"); tplContext.put("reactiverseVMPVersion", MojoUtils.getVersion("vertx-maven-plugin-version")); SetupTemplateUtils.createPom(tplContext, pomFile); assertThat(pomFile).isFile(); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new FileInputStream(pomFile)); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); Properties projectProps = project.getProperties(); assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); assertEquals(project.getGroupId(), "com.example.vertx"); assertEquals(project.getArtifactId(), "vertx-example"); assertEquals(project.getVersion(), "1.0-SNAPSHOT"); assertEquals(projectProps.getProperty("vertx.version"), vertxVersion); assertThat(projectProps.getProperty("vertx-maven-plugin.version")) .contains(MojoUtils.getVersion("vertx-maven-plugin-version")); assertEquals(projectProps.getProperty("vertx.verticle"), "com.example.vertx.MainVerticle"); DependencyManagement dependencyManagement = project.getDependencyManagement(); assertThat(dependencyManagement).isNotNull(); assertThat(dependencyManagement.getDependencies()).isNotEmpty(); Dependency vertxBom = project.getDependencyManagement().getDependencies().get(0); assertThat(vertxBom.getGroupId()).isEqualTo("io.vertx"); assertThat(vertxBom.getArtifactId()).isEqualTo("vertx-dependencies"); assertThat(vertxBom.getVersion()).isEqualTo("${vertx.version}"); assertThat(vertxBom.getType()).isEqualTo("pom"); assertThat(vertxBom.getScope()).isEqualTo("import"); assertThat(project.getDependencies()).isNotEmpty(); Dependency vertxCore =project.getDependencies().get(0); assertThat(vertxCore).isNotNull(); assertThat(vertxCore.getGroupId()).isEqualTo("io.vertx"); assertThat(vertxCore.getArtifactId()).isEqualTo("vertx-core"); }
Example 16
Source File: CreateProjectBuilder.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void performOperation(POMModel model) { org.netbeans.modules.maven.model.pom.Project root = model.getProject(); if (root != null) { MavenProject parent = context.getParent(); if (parent != null) { Parent parentpom = model.getFactory().createParent(); parentpom.setGroupId(parent.getGroupId()); parentpom.setArtifactId(parent.getArtifactId()); parentpom.setVersion(parent.getVersion()); File pfile = FileUtil.normalizeFile(parent.getFile()); String rel = FileUtilities.relativizeFile(context.getProjectDirectory(), pfile); if (rel != null) { if ("..".equals(rel) || "../pom.xml".equals(rel)) { } else { parentpom.setRelativePath(rel); } } else { parentpom.setRelativePath(""); } root.setPomParent(parentpom); } if (parent == null || !context.getGroupId().equals(parent.getGroupId())) { root.setGroupId(context.getGroupId()); } root.setArtifactId(context.getArtifactId()); if (parent == null || !context.getVersion().equals(parent.getVersion())) { root.setVersion(context.getVersion()); } root.setPackaging(packaging); boolean setEncoding = true; if (parent != null) { java.util.Properties parentprops = parent.getProperties(); if (parentprops != null && parentprops.containsKey("project.build.sourceEncoding")) { setEncoding = false; } } if (setEncoding) { Properties props = root.getProperties(); if (props == null) { props = model.getFactory().createProperties(); root.setProperties(props); } props.setProperty("project.build.sourceEncoding", "UTF-8"); } } }
Example 17
Source File: SetupMojoTest.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
@Test public void testVerticleCreatPom() throws Exception { new File("target/unit/nopom").mkdirs(); File pomFile = new File("target/unit/nopom/pom.xml"); String vertxVersion = MojoUtils.getVersion("vertx-core-version"); Map<String, String> tplContext = new HashMap<>(); tplContext.put("mProjectGroupId", "com.example.vertx"); tplContext.put("mProjectArtifactId", "vertx-example"); tplContext.put("mProjectVersion", "1.0-SNAPSHOT"); tplContext.put("vertxVersion", vertxVersion); tplContext.put("vertxVerticle", "com.example.vertx.MainVerticle"); tplContext.put("vmpVersion", MojoUtils.getVersion("vertx-maven-plugin-version")); SetupTemplateUtils.createPom(tplContext, pomFile); assertThat(pomFile).isFile(); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new FileInputStream(pomFile)); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); Properties projectProps = project.getProperties(); assertNotNull(projectProps); assertFalse(projectProps.isEmpty()); assertEquals(project.getGroupId(), "com.example.vertx"); assertEquals(project.getArtifactId(), "vertx-example"); assertEquals(project.getVersion(), "1.0-SNAPSHOT"); assertEquals(projectProps.getProperty("vertx.version"), vertxVersion); assertThat(projectProps.getProperty("vertx-maven-plugin.version")) .contains(MojoUtils.getVersion("vertx-maven-plugin-version")); assertEquals(projectProps.getProperty("vertx.verticle"), "com.example.vertx.MainVerticle"); DependencyManagement dependencyManagement = project.getDependencyManagement(); assertThat(dependencyManagement).isNotNull(); assertThat(dependencyManagement.getDependencies()).isNotEmpty(); Dependency vertxBom = project.getDependencyManagement().getDependencies().get(0); assertThat(vertxBom.getGroupId()).isEqualTo("io.vertx"); assertThat(vertxBom.getArtifactId()).isEqualTo("vertx-stack-depchain"); assertThat(vertxBom.getVersion()).isEqualTo("${vertx.version}"); assertThat(vertxBom.getType()).isEqualTo("pom"); assertThat(vertxBom.getScope()).isEqualTo("import"); assertThat(project.getDependencies()).isNotEmpty(); Dependency vertxCore =project.getDependencies().get(0); assertThat(vertxCore).isNotNull(); assertThat(vertxCore.getGroupId()).isEqualTo("io.vertx"); assertThat(vertxCore.getArtifactId()).isEqualTo("vertx-core"); }
Example 18
Source File: MavenUtil.java From jkube with Eclipse Public License 2.0 | 2 votes |
/** * Return all properties in Maven project, merged with all System properties (-D flags sent to Maven). * <p> * System properties always takes precedence. * * @param project Project to extract Properties from * @return Properties merged */ public static Properties getPropertiesWithSystemOverrides(MavenProject project) { Properties properties = new Properties(project.getProperties()); properties.putAll(System.getProperties()); return properties; }
Example 19
Source File: EnvUtil.java From docker-maven-plugin with Apache License 2.0 | 2 votes |
/** * Return all properties in Maven project, merged with all System properties (-D flags sent to Maven). * * System properties always takes precedence. * * @param project Project to extract Properties from * @return */ public static Properties getPropertiesWithSystemOverrides(MavenProject project) { Properties properties = new Properties(project.getProperties()); properties.putAll(System.getProperties()); return properties; }