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

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

Introduction

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

Prototype

public String getVersion() 

Source Link

Usage

From source file:org.apache.felix.bundleplugin.BundlePlugin.java

License:Apache License

protected Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();

    String bsn;//from w  ww. j  ava2 s . c  o  m
    try {
        bsn = getMaven2OsgiConverter().getBundleSymbolicName(currentProject.getArtifact());
    } catch (Exception e) {
        bsn = currentProject.getGroupId() + "." + currentProject.getArtifactId();
    }

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, getMaven2OsgiConverter().getVersion(currentProject.getVersion()));

    // remove the extraneous Include-Resource and Private-Package entries from generated manifest
    properties.put(Analyzer.REMOVE_HEADERS, Analyzer.INCLUDE_RESOURCE + ',' + Analyzer.PRIVATE_PACKAGE);

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuffer licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        String organizationName = currentProject.getOrganization().getName();
        header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
        properties.put("project.organization.name", organizationName);
        properties.put("pom.organization.name", organizationName);
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getProperties());
    properties.putAll(currentProject.getModel().getProperties());
    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));
    properties.put("project.baseDir", baseDir);
    properties.put("project.build.directory", getBuildDirectory());
    properties.put("project.build.outputdirectory", getOutputDirectory());

    properties.put("classifier", classifier == null ? "" : classifier);

    // Add default plugins
    header(properties, Analyzer.PLUGIN, BlueprintPlugin.class.getName() + "," + SpringXMLType.class.getName());

    return properties;
}

From source file:org.apache.felix.obr.plugin.AbstractFileMojo.java

License:Apache License

/**
 * @return project based on command-line settings, with bundle attached
 * @throws MojoExecutionException/*ww w .  j av a2s.com*/
 */
public MavenProject getProject() throws MojoExecutionException {
    final MavenProject project;
    if (pomFile != null && pomFile.exists()) {
        project = PomHelper.readPom(pomFile);

        groupId = project.getGroupId();
        artifactId = project.getArtifactId();
        version = project.getVersion();
        packaging = project.getPackaging();
    } else {
        project = PomHelper.buildPom(groupId, artifactId, version, packaging);
    }

    if (groupId == null || artifactId == null || version == null || packaging == null) {
        throw new MojoExecutionException("Missing group, artifact, version, or packaging information");
    }

    Artifact bundle = m_factory.createArtifactWithClassifier(groupId, artifactId, version, packaging,
            classifier);
    project.setArtifact(bundle);

    return project;
}

From source file:org.apache.felix.obr.plugin.ResourcesBundle.java

License:Apache License

/**
 * this method gets information form pom.xml to complete missing data from those given by user.
 * @param project project information given by maven
 * @param ebi bundle information extracted from bindex
 * @return true/* ww w.  jav a  2  s. c  o  m*/
 */
public boolean construct(MavenProject project, ExtractBindexInfo ebi) {

    if (ebi.getPresentationName() != null) {
        setPresentationName(ebi.getPresentationName());
        if (project.getName() != null) {
            m_logger.debug("pom property override:<presentationname> " + project.getName());
        }
    } else {
        setPresentationName(project.getName());
    }

    if (ebi.getSymbolicName() != null) {
        setSymbolicName(ebi.getSymbolicName());
        if (project.getArtifactId() != null) {
            m_logger.debug("pom property override:<symbolicname> " + project.getArtifactId());
        }
    } else {
        setSymbolicName(project.getArtifactId());
    }

    if (ebi.getVersion() != null) {
        setVersion(ebi.getVersion());
        if (project.getVersion() != null) {
            m_logger.debug("pom property override:<version> " + project.getVersion());
        }
    } else {
        setVersion(project.getVersion());
    }

    if (ebi.getId() != null) {
        setId(ebi.getId());
    }

    if (ebi.getDescription() != null) {
        setDescription(ebi.getDescription());
        if (project.getDescription() != null) {
            m_logger.debug("pom property override:<description> " + project.getDescription());
        }
    } else {
        setDescription(project.getDescription());
    }

    if (ebi.getDocumentation() != null) {
        setDocumentation(ebi.getDocumentation());
        if (project.getUrl() != null) {
            m_logger.debug("pom property override:<documentation> " + project.getUrl());
        }
    } else {
        setDocumentation(project.getUrl());
    }

    if (ebi.getSource() != null) {
        setSource(ebi.getSource());
        if (project.getScm() != null) {
            m_logger.debug("pom property override:<source> " + project.getScm());
        }
    } else {
        String src = null;
        if (project.getScm() != null) {
            src = project.getScm().getUrl();
        }
        setSource(src);
    }

    if (ebi.getLicense() != null) {
        setLicense(ebi.getLicense());
        String lic = null;
        List l = project.getLicenses();
        Iterator it = l.iterator();
        while (it.hasNext()) {
            if (it.next() != null) {
                m_logger.debug("pom property override:<license> " + lic);
                break;
            }
        }
    } else {
        String lic = null;
        List l = project.getLicenses();
        Iterator it = l.iterator();
        while (it.hasNext()) {
            lic = it.next() + ";";
        }

        setLicense(lic);
    }

    // create the first capability (ie : bundle)
    Capability capability = new Capability();
    capability.setName("bundle");
    PElement p = new PElement();
    p.setN("manifestversion");
    p.setV("2");
    capability.addP(p);

    p = new PElement();
    p.setN("presentationname");
    p.setV(getPresentationName());
    capability.addP(p);

    p = new PElement();
    p.setN("symbolicname");
    p.setV(getSymbolicName());
    capability.addP(p);

    p = new PElement();
    p.setN("version");
    p.setT("version");
    p.setV(getVersion());
    capability.addP(p);

    addCapability(capability);

    List capabilities = ebi.getCapabilities();
    for (int i = 0; i < capabilities.size(); i++) {
        addCapability((Capability) capabilities.get(i));
    }

    List requirement = ebi.getRequirement();
    for (int i = 0; i < requirement.size(); i++) {
        addRequire((Require) requirement.get(i));
    }

    // we also add the goupId
    Category category = new Category();
    category.setId(project.getGroupId());
    addCategory(category);

    return true;
}

From source file:org.apache.felix.obrplugin.ResourcesBundle.java

License:Apache License

/**
 * this method gets information form pom.xml to complete missing data from those given by user.
 * @param project project information given by maven
 * @param ebi bundle information extracted from bindex
 * @param sourcePath path to local sources
 * @param javadocPath path to local javadocs
 * @return true/*www. ja  v a 2  s .  com*/
 */
public boolean construct(MavenProject project, ExtractBindexInfo ebi, String sourcePath, String javadocPath) {

    if (ebi.getPresentationName() != null) {
        setPresentationName(ebi.getPresentationName());
        if (project.getName() != null) {
            m_logger.debug("pom property override:<presentationname> " + project.getName());
        }
    } else {
        setPresentationName(project.getName());
    }

    if (ebi.getSymbolicName() != null) {
        setSymbolicName(ebi.getSymbolicName());
        if (project.getArtifactId() != null) {
            m_logger.debug("pom property override:<symbolicname> " + project.getArtifactId());
        }
    } else {
        setSymbolicName(project.getArtifactId());
    }

    if (ebi.getVersion() != null) {
        setVersion(ebi.getVersion());
        if (project.getVersion() != null) {
            m_logger.debug("pom property override:<version> " + project.getVersion());
        }
    } else {
        setVersion(project.getVersion());
    }

    if (ebi.getId() != null) {
        setId(ebi.getId());
    }

    if (ebi.getDescription() != null) {
        setDescription(ebi.getDescription());
        if (project.getDescription() != null) {
            m_logger.debug("pom property override:<description> " + project.getDescription());
        }
    } else {
        setDescription(project.getDescription());
    }

    // fallback to javadoc if no project URL
    String documentation = project.getUrl();
    if (null == documentation) {
        documentation = javadocPath;
    }

    if (ebi.getDocumentation() != null) {
        setDocumentation(ebi.getDocumentation());
        if (documentation != null) {
            m_logger.debug("pom property override:<documentation> " + documentation);
        }
    } else {
        setDocumentation(documentation);
    }

    if (ebi.getSource() != null) {
        setSource(ebi.getSource());
        if (sourcePath != null) {
            m_logger.debug("pom property override:<source> " + sourcePath);
        }
    } else {
        setSource(sourcePath);
    }

    setJavadoc(javadocPath);

    if (ebi.getLicense() != null) {
        setLicense(ebi.getLicense());
        String lic = null;
        List l = project.getLicenses();
        Iterator it = l.iterator();
        while (it.hasNext()) {
            if (it.next() != null) {
                m_logger.debug("pom property override:<license> " + lic);
                break;
            }
        }
    } else {
        String lic = null;
        List l = project.getLicenses();
        Iterator it = l.iterator();
        while (it.hasNext()) {
            lic = it.next() + ";";
        }

        setLicense(lic);
    }

    // create the first capability (ie : bundle)
    Capability capability = new Capability();
    capability.setName("bundle");
    PElement p = new PElement();
    p.setN("manifestversion");
    p.setV("2");
    capability.addP(p);

    p = new PElement();
    p.setN("presentationname");
    p.setV(getPresentationName());
    capability.addP(p);

    p = new PElement();
    p.setN("symbolicname");
    p.setV(getSymbolicName());
    capability.addP(p);

    p = new PElement();
    p.setN("version");
    p.setT("version");
    p.setV(getVersion());
    capability.addP(p);

    addCapability(capability);

    List capabilities = ebi.getCapabilities();
    for (int i = 0; i < capabilities.size(); i++) {
        addCapability((Capability) capabilities.get(i));
    }

    List requirement = ebi.getRequirement();
    for (int i = 0; i < requirement.size(); i++) {
        addRequire((Require) requirement.get(i));
    }

    List categories = ebi.getCategories();
    for (int i = 0; i < categories.size(); i++) {
        addCategory((Category) categories.get(i));
    }

    // we also add the goupId
    Category category = new Category();
    category.setId(project.getGroupId());
    addCategory(category);

    return true;
}

From source file:org.apache.hyracks.maven.license.LicenseMojo.java

License:Apache License

private String toGav(MavenProject dep) {
    return dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion();
}

From source file:org.apache.hyracks.maven.license.LicenseUtil.java

License:Apache License

static String toGav(MavenProject dep) {
    return dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion();
}

From source file:org.apache.hyracks.maven.license.project.Project.java

License:Apache License

public Project(MavenProject project, String location, File artifactPath) {
    mavenProject = project;/*w w w  . jav  a 2s .co m*/
    name = project.getName();
    groupId = project.getGroupId();
    artifactId = project.getArtifactId();
    version = project.getVersion();
    url = project.getUrl();
    this.artifactPath = artifactPath.getPath();
    setLocation(location);
}

From source file:org.apache.hyracks.maven.license.ProjectFlag.java

License:Apache License

void visit(MavenProject depObj, Properties properties, LicenseMojo licenseMojo) {
    String value = properties.getProperty(propName());
    if (value == null) {
        return;//from   w ww.j a  v a2 s  .c  o  m
    }
    switch (this) {
    case IGNORE_MISSING_EMBEDDED_LICENSE:
    case IGNORE_MISSING_EMBEDDED_NOTICE:
    case IGNORE_LICENSE_OVERRIDE:
    case IGNORE_NOTICE_OVERRIDE:
        if (Stream.of(StringUtils.split(value, ",")).anyMatch(depObj.getVersion()::equals)) {
            licenseMojo.getProjectFlags().put(Pair.of(toGav(depObj), this), Boolean.TRUE);
        } else {
            licenseMojo.getLog().info(propName() + " defined on versions that *do not* match: " + value
                    + " for " + toGav(depObj));
        }
        break;
    case ALTERNATE_LICENSE_FILE:
    case ALTERNATE_NOTICE_FILE:
        for (String spec : StringUtils.split(value, ",")) {
            String[] specSplit = StringUtils.split(spec, ":");
            if (specSplit.length != 2) {
                throw new IllegalArgumentException(spec);
            }
            if (specSplit[0].equals(depObj.getVersion())) {
                licenseMojo.getProjectFlags().put(Pair.of(toGav(depObj), this), specSplit[1]);
            }
        }
        break;
    default:
        throw new IllegalStateException("NYI: " + this);
    }
}

From source file:org.apache.marmotta.maven.plugins.buildinfo.ProjectInfoProvider.java

License:Apache License

public Map<String, String> getInfo(MavenProject project) {
    Date date = new Date();
    Map<String, String> info = new LinkedHashMap<String, String>();
    info.put("project.name", project.getName());
    info.put("build.module", project.getArtifactId());
    info.put("build.version", project.getVersion());
    info.put("build.timestamp", DateFormatUtils.format(date, "EEE, dd MMM yyyy HH:mm:ss z"));
    return info;/*from w w  w.java  2s . c o m*/
}

From source file:org.apache.sling.ide.eclipse.m2e.internal.ContentPackageProjectConfigurator.java

License:Apache License

@Override
public void configure(ProjectConfigurationRequest configRequest, IProgressMonitor progressMonitor)
        throws CoreException {

    IProject project = configRequest.getProject();
    MavenProject mavenProject = configRequest.getMavenProject();
    boolean active = !"false".equalsIgnoreCase(mavenProject.getProperties().getProperty(M2E_ACTIVE));
    if (!active) {
        trace("M2E project configurer for packing type content-package was disabled with property {0}",
                M2E_ACTIVE);/* w ww .j ava2  s . c  om*/
        return;
    }

    String mavenGav = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":"
            + mavenProject.getVersion();

    trace("Configuring Maven project {0} with packaging content-package...", mavenGav);

    // core configuration for sling ide plugin

    Resource folder = MavenProjectUtils.guessJcrRootFolder(mavenProject);

    java.nio.file.Path contentSyncPath = mavenProject.getBasedir().toPath()
            .relativize(Paths.get(folder.getDirectory()));

    String jcrRootPath = contentSyncPath.toString();
    ConfigurationHelper.convertToContentPackageProject(project, progressMonitor,
            Path.fromOSString(jcrRootPath));

    new WtpProjectConfigurer(mavenProject, project, jcrRootPath).configure(progressMonitor);

    trace("Done converting .");
}