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:io.fabric8.maven.enricher.fabric8.DocLinkEnricher.java

License:Apache License

protected String findDocumentationUrl() {
    DistributionManagement distributionManagement = findProjectDistributionManagement();
    if (distributionManagement != null) {
        Site site = distributionManagement.getSite();
        if (site != null) {
            String url = site.getUrl();
            if (Strings.isNotBlank(url)) {
                // lets replace any properties...
                MavenProject project = getProject();
                if (project != null) {
                    url = replaceProperties(url, project.getProperties());
                }/*from ww w.  j  a  v a2 s .co  m*/

                // lets convert the internal dns name to a public name
                try {
                    String urlToParse = url;
                    int idx = url.indexOf("://");
                    if (idx > 0) {
                        // lets strip any previous schemes such as "dav:"
                        int idx2 = url.substring(0, idx).lastIndexOf(':');
                        if (idx2 >= 0 && idx2 < idx) {
                            urlToParse = url.substring(idx2 + 1);
                        }
                    }
                    URL u = new URL(urlToParse);
                    String serviceName = u.getHost();
                    String protocol = u.getProtocol();
                    if (isOnline()) {
                        // lets see if the host name is a service name in which case we'll resolve to the public URL
                        String publicUrl = getExternalServiceURL(serviceName, protocol);
                        if (Strings.isNotBlank(publicUrl)) {
                            return URLUtils.pathJoin(publicUrl, u.getPath());
                        }
                    }
                } catch (MalformedURLException e) {
                    getLog().error("Failed to parse URL: %s. %s", url, e);
                }
                return url;
            }
        }
    }
    return null;
}

From source file:io.fabric8.maven.enricher.standard.DebugEnricher.java

License:Apache License

private boolean debugEnabled() {
    MavenProject project = getContext().getProject();
    if (project != null) {
        String value = project.getProperties().getProperty(ENABLE_DEBUG_MAVEN_PROPERTY);
        if (isTrueFlag(value)) {
            return true;
        }/*from  w  ww  . jav a 2s  .  c  o  m*/
        ;
    }
    return isTrueFlag(System.getProperty(ENABLE_DEBUG_MAVEN_PROPERTY));
}

From source file:io.fabric8.maven.plugin.mojo.build.ApplyMojo.java

License:Apache License

protected static Properties getProjectAndFabric8Properties(MavenProject project) {
    Properties properties = project.getProperties();
    properties.putAll(project.getProperties());
    // let system properties override so we can read from the command line
    properties.putAll(System.getProperties());
    return properties;
}

From source file:io.fabric8.vertx.maven.plugin.Verify.java

License:Apache License

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);/*from   ww w .  j a  v a 2  s  . c  om*/
    assertFalse(projectProps.isEmpty());
    assertEquals(projectProps.getProperty("vertx.projectVersion"), "3.4.0");
}

From source file:io.sundr.maven.GenerateBomMojo.java

License:Apache License

/**
 * Returns the generated {@link org.apache.maven.project.MavenProject} to build.
 * This version of the project contains all the stuff needed for building (parents, profiles, properties etc).
 *
 * @param project The source {@link org.apache.maven.project.MavenProject}.
 * @param config  The {@link io.sundr.maven.BomConfig}.
 * @return The build {@link org.apache.maven.project.MavenProject}.
 *//* w ww. j  a v a 2 s.co  m*/
private static MavenProject toBuild(MavenProject project, BomConfig config) {
    File outputDir = new File(project.getBuild().getOutputDirectory());
    File bomDir = new File(outputDir, config.getArtifactId());
    File generatedBom = new File(bomDir, BOM_NAME);

    MavenProject toBuild = project.clone();
    //we want to avoid recursive "generate-bom".
    toBuild.setExecutionRoot(false);
    toBuild.setFile(generatedBom);
    toBuild.getModel().setPomFile(generatedBom);
    toBuild.setModelVersion(project.getModelVersion());

    toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(),
            project.getArtifact().getScope(), project.getArtifact().getType(),
            project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler()));

    toBuild.setParent(project.getParent());
    toBuild.getModel().setParent(project.getModel().getParent());

    toBuild.setGroupId(project.getGroupId());
    toBuild.setArtifactId(config.getArtifactId());
    toBuild.setVersion(project.getVersion());
    toBuild.setPackaging("pom");
    toBuild.setName(config.getName());
    toBuild.setDescription(config.getDescription());

    toBuild.setUrl(project.getUrl());
    toBuild.setLicenses(project.getLicenses());
    toBuild.setScm(project.getScm());
    toBuild.setDevelopers(project.getDevelopers());
    toBuild.setDistributionManagement(project.getDistributionManagement());
    toBuild.getModel().setProfiles(project.getModel().getProfiles());

    //We want to avoid having the generated stuff wiped.
    toBuild.getProperties().put("clean.skip", "true");
    toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath());
    toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath());
    for (String key : config.getProperties().stringPropertyNames()) {
        toBuild.getProperties().put(key, config.getProperties().getProperty(key));
    }
    return toBuild;
}

From source file:it.session.maven.plugin.TilesMavenLifecycleParticipant.java

License:Apache License

protected void mergeTile(MavenProject currentProject, String propertyName,
        RepositorySystemSession repositorySystemSession) throws MavenExecutionException {
    String propertyValue = currentProject.getProperties().getProperty(propertyName);
    StringTokenizer propertyTokens = new StringTokenizer(propertyValue, ":");

    String groupId = propertyTokens.nextToken();
    String artifactId = propertyTokens.nextToken();
    String version = propertyTokens.nextToken();

    String currentTileInformation = String.format("'%s:%s:%s'", groupId, artifactId, version);

    try {/*  w w  w . j  a  va2s  . co m*/
        File artifactFile = this.resolveArtifact(currentProject, groupId, artifactId, version,
                repositorySystemSession);

        Model tileModel = this.reader.read(new FileInputStream(artifactFile));
        this.modelMerger.merge(currentProject.getModel(), tileModel, false, null);

        //If invoked by tests, logger is null
        //@TODO properly inject logger on TilesMavenLifecycleParticipantTest.java
        if (logger != null) {
            logger.info(String.format("Loaded Maven Tile " + currentTileInformation));
        }

    } catch (FileNotFoundException e) {
        throw new MavenExecutionException("Error loading tiles " + currentTileInformation, e);
    } catch (XmlPullParserException e) {
        throw new MavenExecutionException("Error building tiles " + currentTileInformation, e);
    } catch (IOException e) {
        throw new MavenExecutionException("Error parsing tiles " + currentTileInformation, e);
    } catch (MojoExecutionException e) {
        throw new MavenExecutionException("Error retrieving tiles " + currentTileInformation, e);
    }
}

From source file:it.session.maven.plugin.TilesMavenLifecycleParticipant.java

License:Apache License

private void mergeTiles(MavenProject currentProject, MavenSession mavenSession) throws MavenExecutionException {
    Enumeration propertyNames = currentProject.getProperties().propertyNames();
    while (propertyNames.hasMoreElements()) {
        String propertyName = (String) propertyNames.nextElement();
        if (propertyName.startsWith(TILE_PROPERTY_PREFIX)) {
            mergeTile(currentProject, propertyName, mavenSession.getRepositorySession());
        }//from  ww w .ja  v  a2 s.co m
    }
}

From source file:net.oneandone.maven.plugins.prerelease.util.PrepareExecutionListener.java

License:Apache License

private void initialProperties(MavenProject project) {
    for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
        if (entry.getValue() instanceof String) {
            initialProperties.put((String) entry.getKey(), (String) entry.getValue());
        } else {//  w w w  .jav  a 2  s.  com
            throw new IllegalStateException();
        }
    }
}

From source file:net.oneandone.maven.plugins.prerelease.util.PrepareExecutionListener.java

License:Apache License

public void saveModified(MavenProject project) {
    String old;/*from w  w w  .  j a  v  a 2  s . c  om*/
    Map<String, String> deployProperties;

    deployProperties = prerelease.descriptor.deployProperties;
    for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
        if (entry.getValue() instanceof String) {
            old = initialProperties.get(entry.getKey());
            if (!entry.getValue().equals(old)) {
                deployProperties.put((String) entry.getKey(), (String) entry.getValue());
            }
        }
    }
    try {
        prerelease.descriptor.save(prerelease.target);
    } catch (IOException e) {
        throw new RuntimeException("TODO", e);
    }
}

From source file:net.oneandone.maven.plugins.prerelease.util.PromoteExecutionListener.java

License:Apache License

@Override
public void projectStarted(ExecutionEvent event) {
    MavenProject project;
    Artifact projectArtifact;//from w ww  .  j  a v a2 s .  c  o m
    Versioning versioning;
    ArtifactRepositoryMetadata metadata;
    GroupRepositoryMetadata groupMetadata;

    project = event.getSession().getCurrentProject();
    try {
        prerelease.artifactFiles(project, projectHelper);
        project.getProperties().putAll(prerelease.descriptor.deployProperties);
        if (prerelease.descriptor.deployPluginMetadata) {
            // from http://svn.apache.org/viewvc/maven/plugin-tools/tags/maven-plugin-tools-3.2/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java

            projectArtifact = project.getArtifact();
            versioning = new Versioning();
            versioning.setLatest(projectArtifact.getVersion());
            versioning.updateTimestamp();
            metadata = new ArtifactRepositoryMetadata(projectArtifact, versioning);
            projectArtifact.addMetadata(metadata);
            groupMetadata = new GroupRepositoryMetadata(project.getGroupId());
            groupMetadata.addPluginMapping(
                    PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId()),
                    project.getArtifactId(), project.getName());

            projectArtifact.addMetadata(groupMetadata);
        }
    } catch (IOException e) {
        throw new RuntimeException("TODO", e);
    }
    super.projectStarted(event);
}