List of usage examples for org.apache.maven.project MavenProject getProperties
public Properties getProperties()
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze POM project to see if it actually just imports an existing bundle * /* w ww. j a v a 2 s . c om*/ * @param project Maven POM project * @return imported bundle, null if it isn't a import project */ private Dependency findImportee(MavenProject project) { Properties properties = project.getProperties(); Dependency importee = new Dependency(); // original Pax-Construct importee.setGroupId(properties.getProperty("bundle.groupId")); importee.setArtifactId(properties.getProperty("bundle.artifactId")); importee.setVersion(properties.getProperty("bundle.version")); if (importee.getArtifactId() != null) { return importee; } return null; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze bundle project to find the primary namespace it provides * // w w w . j av a2 s. c o m * @param project Maven project * @return primary Java namespace */ private String findBundleNamespace(MavenProject project) { Properties properties = project.getProperties(); // Pax-Construct v2 String namespace = properties.getProperty("bundle.namespace"); if (null == namespace) { // original Pax-Construct namespace = properties.getProperty("bundle.package"); String sourcePath = project.getBuild().getSourceDirectory(); if (null == namespace && new File(sourcePath).exists()) { namespace = findPrimaryPackage(sourcePath); } } return namespace; }
From source file:org.ops4j.pax.construct.lifecycle.EclipseOSGiMojo.java
License:Apache License
/** * Provide better naming for Pax-Construct generated OSGi bundles * //from w w w . ja v a2 s . c o m * @param project current Maven project * @param addVersion when true, add the project version to the name * @return an Eclipse friendly name for the bundle */ private static String getEclipseProjectName(MavenProject project, boolean addVersion) { String projectName = project.getProperties().getProperty("bundle.symbolicName"); if (null == projectName) { // fall back to standard "groupId.artifactId" but try to eliminate duplicate segments projectName = PomUtils.getCompoundId(project.getGroupId(), project.getArtifactId()); } if (addVersion) { // check for wrapper version, which reflects the version of the wrapped contents String projectVersion = project.getProperties().getProperty("wrapped.version"); if (null == projectVersion) { projectVersion = project.getVersion(); } return projectName + " [" + projectVersion + ']'; } return projectName; }
From source file:org.overlord.sramp.integration.java.artifactbuilder.MavenPomArtifactBuilder.java
License:Apache License
@Override public ArtifactBuilder buildArtifacts(BaseArtifactType primaryArtifact, ArtifactContent artifactContent) throws IOException { super.buildArtifacts(primaryArtifact, artifactContent); try {//from ww w .j ava 2 s. c o m Model model = new MavenXpp3Reader().read(getContentStream()); MavenProject project = new MavenProject(model); ((ExtendedDocument) primaryArtifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (primaryArtifact.getDescription() == null) primaryArtifact.setDescription(project.getDescription()); if (primaryArtifact.getName() == null) primaryArtifact.setName(project.getName()); if (primaryArtifact.getVersion() == null) primaryArtifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } return this; } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.overlord.sramp.integration.java.deriver.MavenPomDeriver.java
License:Apache License
/** * @see org.overlord.sramp.common.derived.ArtifactDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream) *//*w w w . java 2 s .c om*/ @Override public Collection<BaseArtifactType> derive(BaseArtifactType artifact, InputStream contentStream) throws IOException { List<BaseArtifactType> derivedArtifacts = new ArrayList<BaseArtifactType>(); try { Model model = new MavenXpp3Reader().read(contentStream); MavenProject project = new MavenProject(model); ((ExtendedDocument) artifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (artifact.getDescription() == null) artifact.setDescription(project.getDescription()); if (artifact.getName() == null) artifact.setName(project.getName()); if (artifact.getVersion() == null) artifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } return derivedArtifacts; }
From source file:org.ow2.mind.adl.maven.plugin.Properties.java
License:Open Source License
public List<String> getArguments(MavenProject project) { java.util.Properties p = new java.util.Properties(); List<String> arguments = new ArrayList<String>(p.size()); if (file != null) { try {//w w w .j a va 2 s . c o m final FileInputStream fileInputStream = new FileInputStream(file); p.load(fileInputStream); for (Map.Entry<Object, Object> entry : p.entrySet()) { String name = (String) entry.getKey(); String value = (String) entry.getValue(); /* * Replace all occurrences of ${*} by the corresponding property value */ Pattern pattern = Pattern.compile("\\$\\{[^\\$]*\\}"); Matcher matcher = pattern.matcher(value); while (matcher.find()) { String propertyName = matcher.group(); String key = propertyName.substring(2, propertyName.length() - 1); /* * The property is searched first in the project properties, then in * the system properties and finally in the environment variables */ String propertyValue = project.getProperties().getProperty(key); if (propertyValue == null) { propertyValue = System.getProperty(key); if (propertyValue == null) { propertyValue = System.getenv(key); } } if (propertyValue != null) { value = value.replace(propertyName, propertyValue); matcher.reset(value); } } arguments.add("-" + name + "=" + value); } return arguments; } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } throw new RuntimeException("Unable to find or read properties from " + file); } return arguments; }
From source file:org.phpmaven.plugin.pear.DefaultMojo.java
License:Apache License
protected String getPackageKey(final MavenProject prj) { final String prop = prj.getProperties().getProperty("flow3.ns"); if (prop != null) return prop; return "F3." + prj.getArtifactId(); }
From source file:org.scoverage.plugin.SCoverageForkedLifecycleConfigurator.java
License:Apache License
/** * Configures project and dependent modules in multi-module project when entering forked {@code scoverage} * life cycle./*from w w w . ja v a 2 s .co m*/ * * @param project Maven project in {@code scoverage} forked life cycle. * @param reactorProjects all reactor Maven projects. * @param additionalProjectPropertiesMap additional project properties to set. */ public static void afterForkedLifecycleEnter(MavenProject project, List<MavenProject> reactorProjects, Map<String, String> additionalProjectPropertiesMap) { File classesDirectory = new File(project.getBuild().getOutputDirectory()); File scoverageClassesDirectory = new File(classesDirectory.getParentFile(), "scoverage-" + classesDirectory.getName()); project.getArtifact().setFile(null); project.getBuild().setOutputDirectory(scoverageClassesDirectory.getAbsolutePath()); if (additionalProjectPropertiesMap != null) { for (Map.Entry<String, String> entry : additionalProjectPropertiesMap.entrySet()) { project.getProperties().put(entry.getKey(), entry.getValue()); } } for (MavenProject reactorProject : reactorProjects) { if (reactorProject != project) { if (reactorProject.getProperties().containsKey(PROP_FORKED_OUTPUT_DIRECTORY)) { String forkedOutputDirectory = (String) reactorProject.getProperties() .remove/* get */(PROP_FORKED_OUTPUT_DIRECTORY); reactorProject.getProperties().put(PROP_ORIG_OUTPUT_DIRECTORY, reactorProject.getBuild().getOutputDirectory()); reactorProject.getBuild().setOutputDirectory(forkedOutputDirectory); } if (reactorProject.getProperties().containsKey(PROP_FORKED_ARTIFACT_FILE)) { String forkedArtifactFilePath = (String) reactorProject.getProperties() .remove/* get */(PROP_FORKED_ARTIFACT_FILE); File originalArtifactFile = reactorProject.getArtifact().getFile(); reactorProject.getProperties().put(PROP_ORIG_ARTIFACT_FILE, originalArtifactFile == null ? "" : originalArtifactFile.getAbsolutePath()); reactorProject.getArtifact() .setFile("".equals(forkedArtifactFilePath) ? null : new File(forkedArtifactFilePath)); } } } }
From source file:org.scoverage.plugin.SCoverageForkedLifecycleConfigurator.java
License:Apache License
/** * Restores original configuration after leaving forked {@code scoverage} life cycle. * <br>/*from w ww. ja va2s . c o m*/ * {@code project} is a project in default life cycle, {@code project.getExecutionProject()} * is a project in just finished forked {@code scoverage} life cycle. * * @param project Maven project in default life cycle. * @param reactorProjects all reactor Maven projects. */ public static void afterForkedLifecycleExit(MavenProject project, List<MavenProject> reactorProjects) { String forkedOutputDirectory = project.getExecutionProject().getBuild().getOutputDirectory(); project.getProperties().put(PROP_FORKED_OUTPUT_DIRECTORY, forkedOutputDirectory); File forkedArtifactFile = project.getExecutionProject().getArtifact().getFile(); project.getProperties().put(PROP_FORKED_ARTIFACT_FILE, forkedArtifactFile != null ? forkedArtifactFile.getAbsolutePath() : ""); // Restore changed outputDirectory and artifact.file in other reactor projects for (MavenProject reactorProject : reactorProjects) { if (reactorProject != project) { if (reactorProject.getProperties().containsKey(PROP_ORIG_OUTPUT_DIRECTORY)) { String originalOutputDirectory = (String) reactorProject.getProperties() .remove(PROP_ORIG_OUTPUT_DIRECTORY); forkedOutputDirectory = reactorProject.getBuild().getOutputDirectory(); reactorProject.getProperties().put(PROP_FORKED_OUTPUT_DIRECTORY, forkedOutputDirectory); reactorProject.getBuild().setOutputDirectory(originalOutputDirectory); } if (reactorProject.getProperties().containsKey(PROP_ORIG_ARTIFACT_FILE)) { String originalArtifactFilePath = (String) reactorProject.getProperties() .remove/* get */(PROP_ORIG_ARTIFACT_FILE); forkedArtifactFile = reactorProject.getArtifact().getFile(); reactorProject.getProperties().put(PROP_FORKED_ARTIFACT_FILE, forkedArtifactFile == null ? "" : forkedArtifactFile.getAbsolutePath()); reactorProject.getArtifact().setFile( "".equals(originalArtifactFilePath) ? null : new File(originalArtifactFilePath)); } } } }
From source file:org.seasar.uruma.eclipath.util.ProjectUtil.java
License:Apache License
/** * Returns eclipse workspace directory. First, this method determine the * eclipse workspace directory from pom.xml's directory. Second, determines * from "eclipse.workspace" property key which defined in the pom.xml or * settinegs.xml. If, this method can't find the workspace directory, * returns {@code null}./*from www . j a v a 2s . c o m*/ * * @param project * Maven project * @return workspace directory, or {@code null} */ public static File getWorkspaceDir(MavenProject project) { // TODO Dealing with multi projects. File workspaceDir = project.getFile().getParentFile().getParentFile(); if (isValidWorkspaceLocation(workspaceDir)) { return workspaceDir; } else { String prop = project.getProperties().getProperty(PROP_KEY_ECLIPSE_WORKSPACE); if (prop != null) { workspaceDir = new File(prop); if (isValidWorkspaceLocation(workspaceDir)) { return workspaceDir; } } Logger.warn("Can't find eclipse workspace."); return null; } }