Example usage for org.apache.maven.project MavenProject getProperties

List of usage examples for org.apache.maven.project MavenProject getProperties

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getProperties.

Prototype

public Properties getProperties() 

Source Link

Usage

From source file:com.lukegb.mojo.build.GitDescribeMojo.java

License:Apache License

/**
 * Generic property setter./*w  ww . j a  v  a2  s. c o  m*/
 */
private void setProperty(String property, String value) {
    if (value != null) {
        project.getProperties().put(property, value);
        if (setReactorProjectsProperties && reactorProjects != null) {
            for (Object reactorProject : reactorProjects) {
                MavenProject nextProj = (MavenProject) reactorProject;
                nextProj.getProperties().put(property, value);
            }
        }
    }
}

From source file:com.oracle.istack.maven.PropertyResolver.java

License:Open Source License

/**
 *
 * @param project maven project//from  w w  w.  j  a v  a  2  s  . co  m
 * @throws FileNotFoundException properties not found
 * @throws IOException IO error
 * @throws XmlPullParserException error parsing xml
 */
public void resolveProperties(MavenProject project)
        throws FileNotFoundException, IOException, XmlPullParserException {
    logger.info("Resolving properties for " + project.getGroupId() + ":" + project.getArtifactId());

    Model model = null;
    FileReader reader;
    try {
        reader = new FileReader(project.getFile());
        model = mavenreader.read(reader);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    }
    MavenProject loadedProject = new MavenProject(model);

    DependencyManagement dm = loadedProject.getDependencyManagement();
    if (dm == null) {
        logger.warn("No dependency management section found in: " + loadedProject.getGroupId() + ":"
                + loadedProject.getArtifactId());
        return;
    }

    List<Dependency> depList = dm.getDependencies();

    DependencyResult result;
    for (Dependency d : depList) {
        if ("import".equals(d.getScope())) {
            try {
                String version = d.getVersion();
                logger.info("Imported via import-scope: " + d.getGroupId() + ":" + d.getArtifactId() + ":"
                        + version);
                if (version.contains("$")) {
                    version = properties
                            .getProperty(version.substring(version.indexOf('{') + 1, version.lastIndexOf('}')));
                    logger.info("Imported version resolved to: " + version);
                }
                d.setVersion(version);
                d.setType("pom");
                d.setClassifier("pom");
                result = DependencyResolver.resolve(d, pluginRepos, repoSystem, repoSession);
                Artifact a = result.getArtifactResults().get(0).getArtifact();
                reader = new FileReader(a.getFile());
                Model m = mavenreader.read(reader);
                MavenProject p = new MavenProject(m);
                p.setFile(a.getFile());
                for (Map.Entry<Object, Object> e : p.getProperties().entrySet()) {
                    logger.info("Setting property: " + (String) e.getKey() + ":" + (String) e.getValue());
                    properties.setProperty((String) e.getKey(), (String) e.getValue());
                }

                resolveProperties(p);
            } catch (DependencyResolutionException ex) {
                Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:com.paulhammant.buildradiatorextension.BuildRadiatorEventSpy.java

License:Open Source License

@Override
public void onEvent(Object event) throws Exception {

    try {/*from w ww.  j  a  v  a  2  s .c  om*/

        try {
            if (event instanceof ExecutionEvent) {
                ExecutionEvent executionEvent = (ExecutionEvent) event;
                MavenProject project = executionEvent.getProject();
                String lifecyclePhase = executionEvent.getMojoExecution().getLifecyclePhase();
                String phase = lifecyclePhase.substring(lifecyclePhase.lastIndexOf(':') + 1);
                String execution = executionEvent.getMojoExecution().getExecutionId();

                String currentArtifactId = project.getArtifactId();

                if (!projectPropertiesDone) {
                    this.buildRadiatorInterop.projectProperties(project.getProperties(),
                            project.getArtifactId());
                    projectPropertiesDone = true;
                }

                String status = executionEvent.getType().toString();
                if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) {
                    status = "started";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoFailed) {
                    status = "failed";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded) {
                    status = "passed";
                }

                this.buildRadiatorInterop.executionEvent(phase, execution, currentArtifactId, status);

            }
            if (event instanceof DefaultMavenExecutionResult) {
                DefaultMavenExecutionResult dmer = (DefaultMavenExecutionResult) event;
                this.buildRadiatorInterop.executionResult(
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildSuccess,
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildFailure);
            }
        } catch (NullPointerException e) {
            // do nothing
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTestCase.java

License:Apache License

/**
 * Copy the project specified into a temporary testing directory. Create the {@link MavenProject} and
 * {@link ManifestUpdateMojo}, configure it from the <code>plugin-config.xml</code> and return the created Mojo.
 * <p>/*from   w w  w.ja  v  a 2s  .  c  o  m*/
 * Note: only configuration entries supplied in the plugin-config.xml are presently configured in the mojo returned.
 * That means and 'default-value' settings are not automatically injected by this testing framework (or plexus
 * underneath that is suppling this functionality)
 * 
 * @param resourceProject
 *            the name of the goal to look for in the <code>plugin-config.xml</code> that the configuration will be
 *            pulled from.
 * @param resourceProject
 *            the resourceProject path (in src/test/resources) to find the example/test project.
 * @return the created mojo (unexecuted)
 * @throws Exception
 *             if there was a problem creating the mojo.
 */
protected T createMojo(String resourceProject) throws Exception {
    // Establish test details project example
    String testResourcePath = "src/test/resources/" + resourceProject;
    testResourcePath = FilenameUtils.separatorsToSystem(testResourcePath);
    File exampleDir = new File(getBasedir(), testResourcePath);
    Assert.assertTrue("Path should exist: " + exampleDir, exampleDir.exists());

    // Establish the temporary testing directory.
    String testingPath = "target/tests/" + this.getClass().getSimpleName() + "." + getName();
    testingPath = FilenameUtils.separatorsToSystem(testingPath);
    File testingDir = new File(getBasedir(), testingPath);

    if (testingDir.exists()) {
        FileUtils.cleanDirectory(testingDir);
    } else {
        Assert.assertTrue("Could not create directory: " + testingDir, testingDir.mkdirs());
    }

    // Copy project example into temporary testing directory
    // to avoid messing up the good source copy, as mojo can change
    // the AndroidManifest.xml file.
    FileUtils.copyDirectory(exampleDir, testingDir);

    // Prepare MavenProject
    final MavenProject project = new MojoProjectStub(testingDir);

    // Setup Mojo
    PlexusConfiguration config = extractPluginConfiguration("android-maven-plugin", project.getFile());
    @SuppressWarnings("unchecked")
    final T mojo = (T) lookupMojo(getPluginGoalName(), project.getFile());

    // Inject project itself
    setVariableValueToObject(mojo, "project", project);

    // Configure the rest of the pieces via the PluginParameterExpressionEvaluator
    //  - used for ${plugin.*}
    MojoDescriptor mojoDesc = new MojoDescriptor();
    // - used for error messages in PluginParameterExpressionEvaluator
    mojoDesc.setGoal(getPluginGoalName());
    MojoExecution mojoExec = new MojoExecution(mojoDesc);
    // - Only needed if we start to use expressions like ${settings.*}, ${localRepository}, ${reactorProjects}
    // MavenSession context = null; // Messy to declare, would rather avoid using it.
    // - Used for ${basedir} relative paths
    PathTranslator pathTranslator = new DefaultPathTranslator();
    // - Declared to prevent NPE from logging events in maven core
    Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, mojo.getClass().getName());

    MavenSession context = createMock(MavenSession.class);

    expect(context.getExecutionProperties()).andReturn(project.getProperties());
    expect(context.getCurrentProject()).andReturn(project);
    replay(context);

    // Declare evalator that maven itself uses.
    ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(context, mojoExec, pathTranslator,
            logger, project, project.getProperties());
    // Lookup plexus configuration component
    ComponentConfigurator configurator = (ComponentConfigurator) lookup(ComponentConfigurator.ROLE, "basic");
    // Configure mojo using above
    ConfigurationListener listener = new DebugConfigurationListener(logger);
    configurator.configureComponent(mojo, config, evaluator, getContainer().getContainerRealm(), listener);

    return mojo;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.BuildPropertiesFileHelper.java

License:Apache License

/**
 * Fetches the project properties and if <code>null</code> returns a new empty
 * properties instance that is associated with the project.
 *
 * @param project the project whose properties are requested.
 * @return the properties of the project.
 *///from   w  w w. ja v  a 2  s.  c  o m
public Properties getProjectProperties(final MavenProject project) {
    Properties projectProperties = project.getProperties();
    if (projectProperties == null) {
        projectProperties = new Properties();
        project.getModel().setProperties(projectProperties);
    }

    return projectProperties;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.maven.MavenPropertyHelper.java

License:Apache License

private static String getPropertiesProperty(final MavenProject project, final String name) {
    String value = null;/*from w ww.  j a  va 2  s . c om*/
    final Properties properties = project.getProperties();
    if (properties != null) {
        value = properties.getProperty(name);
    }

    if (value == null) {
        value = getPropertiesPropertyFromParent(project, name);
    }

    return value;
}

From source file:com.redhat.rcm.version.mgr.session.ManagedInfo.java

License:Open Source License

void addBOM(final File bom, final MavenProject project) throws VManException {
    final FullProjectKey key = new FullProjectKey(project.getGroupId(), project.getArtifactId(),
            project.getVersion());// w  ww . j  a v a 2s.  c  om
    if (bomProjects.containsKey(key)) {
        return;
    }

    bomProjects.put(key, project);

    startBomMap(bom, project.getGroupId(), project.getArtifactId(), project.getVersion());

    if (project.getDependencyManagement() != null
            && project.getDependencyManagement().getDependencies() != null) {
        for (final Dependency dep : project.getDependencyManagement().getDependencies()) {
            mapDependency(bom, dep);
        }
    }

    final Properties properties = project.getProperties();
    if (properties != null) {
        final String relocations = properties.getProperty(RELOCATIONS_KEY);
        logger.info("Got relocations:\n\n" + relocations);
        if (relocations != null) {
            logger.warn("[DEPRECATED] BOM-based coordinate relocations have been replaced by the "
                    + Cli.RELOCATIONS_PROPERTY
                    + " configuration, which specifies a URL to a properties file. Please use this instead.");

            relocatedCoords.addBomRelocations(bom, parseProperties(relocations));
        }

        final String mappings = properties.getProperty(MAPPINGS_KEY);
        logger.info("Got mappings:\n\n" + mappings);
        if (mappings != null) {
            logger.warn("[DEPRECATED] BOM-based property mappings have been replaced by the "
                    + Cli.PROPERTY_MAPPINGS_PROPERTY
                    + " configuration, which specifies a URL to a properties file. Please use this instead.");

            propertyMappings.addBomPropertyMappings(bom, project.getProperties(), parseProperties(mappings));
        }
    }

    logger.info("Updating property mappings from " + project.getId());

    // NOTE: parent properties are inherited into the BOM by the time the MavenProject instance
    // is created, so we don't need to traverse up to the parent; we should have everything here.
    propertyMappings.updateProjectMap(project.getProperties());
}

From source file:com.rodiontsev.maven.plugins.buildinfo.providers.DeclaredPropertiesProvider.java

License:Apache License

@Override
public Map<String, String> getInfo(final MavenProject project, final BuildInfoMojo mojo) {
    Map<String, String> info = new LinkedHashMap<String, String>();

    new InfoWriter().write(info, mojo.getDeclaredProperties(), new PropertyMapper() {
        @Override/*from w  ww  . j av a  2 s  .  c  o  m*/
        public String mapProperty(final String propertyName) {
            return (String) project.getProperties().get(propertyName);
        }
    });

    return info;
}

From source file:com.runwaysdk.business.generation.maven.MavenClasspathBuilder.java

License:Open Source License

public static MavenProject loadProject(File pomFile) throws IOException, XmlPullParserException {
    MavenProject ret = null;//from w  w  w .  j av a2s.  com
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();

    if (pomFile != null && pomFile.exists()) {
        FileReader reader = null;

        try {
            reader = new FileReader(pomFile);
            Model model = mavenReader.read(reader);
            model.setPomFile(pomFile);

            List<Repository> repositories = model.getRepositories();
            Properties properties = model.getProperties();
            properties.setProperty("basedir", pomFile.getParent());

            Parent parent = model.getParent();
            if (parent != null) {
                File parentPom = new File(pomFile.getParent(), parent.getRelativePath());
                MavenProject parentProj = loadProject(parentPom);

                if (parentProj == null) {
                    throw new CoreException("Unable to load parent project at " + parentPom.getAbsolutePath());
                }

                repositories.addAll(parentProj.getRepositories());
                model.setRepositories(repositories);

                properties.putAll(parentProj.getProperties());
            }

            ret = new MavenProject(model);
        } finally {
            reader.close();
        }
    }

    return ret;
}

From source file:com.sap.prd.mobile.ios.mios.FolderLayout.java

License:Apache License

/**
 * Checks if the source folder location has been explicitly set by the "xcode.sourceDirectory". If
 * not the default "src/xcode" is returned.
 *//*from  w ww .j  a va 2  s . c o m*/
static File getSourceFolder(MavenProject project) {
    final Properties projectProperties = project.getProperties();

    if (projectProperties.containsKey(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY)) {
        return new File(project.getBasedir(),
                projectProperties.getProperty(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY));
    }
    return new File(project.getBasedir(), XCodeDefaultConfigurationMojo.DEFAULT_XCODE_SOURCE_DIRECTORY);

}