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

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

Introduction

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

Prototype

public Organization getOrganization() 

Source Link

Usage

From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java

License:Apache License

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

    String bsn;//from  w w w  .j  av a  2  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(Constants.REMOVEHEADERS, 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) {
        if (currentProject.getOrganization().getName() != 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());
    if (m_mavenSession != null) {
        try {
            // don't pass upper-case session settings to bnd as they end up in the manifest
            Properties sessionProperties = m_mavenSession.getExecutionProperties();
            for (Enumeration e = sessionProperties.propertyNames(); e.hasMoreElements();) {
                String key = (String) e.nextElement();
                if (key.length() > 0 && !Character.isUpperCase(key.charAt(0))) {
                    properties.put(key, sessionProperties.getProperty(key));
                }
            }
        } catch (Exception e) {
            getLog().warn("Problem with Maven session properties: " + e.getLocalizedMessage());
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", getBase(currentProject));
    properties.put("project.build.directory", getBuildDirectory());
    properties.put("project.build.outputdirectory", getOutputDirectory());

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

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

    return properties;
}

From source file:org.rapidoid.plugin.app.AbstractRapidoidMojo.java

License:Apache License

private void addJarManifest(String uberJar, MavenProject project, String mainClass) throws IOException {
    Path path = Paths.get(uberJar);
    URI uri = URI.create("jar:" + path.toUri());

    String user = System.getProperty("user.name");

    String manifestContent = IO.load("manifest-template.mf").replace("$user", user)
            .replace("$java", Msc.javaVersion()).replace("$name", project.getName())
            .replace("$version", project.getVersion()).replace("$groupId", project.getGroupId())
            .replace("$organization",
                    project.getOrganization() != null ? U.or(project.getOrganization().getName(), "?") : "?")
            .replace("$url", U.or(project.getUrl(), "?")).replace("$main", U.safe(mainClass));

    try (FileSystem fs = FileSystems.newFileSystem(uri, U.<String, Object>map())) {
        Path manifest = fs.getPath("META-INF/MANIFEST.MF");
        try (Writer writer = Files.newBufferedWriter(manifest, StandardCharsets.UTF_8,
                StandardOpenOption.CREATE)) {
            writer.write(manifestContent);
        }/*w  ww. j av  a  2s .co  m*/
    }
}

From source file:org.sonatype.m2e.mavenarchiver.internal.AbstractMavenArchiverConfigurator.java

License:Open Source License

/**
 * Checks if the MANIFEST.MF needs to be regenerated. That is if :
 * <ul><li>it doesn't already exist</li>
 * <li>the maven project configuration changed</li>
 * <li>the maven project dependencies changed</li>
 * </ul> /*w  w  w. j  a v a  2s.  c om*/
 * Implementations can override this method to add pre-conditions.
 * @param manifest the MANIFEST.MF file to control
 * @param oldFacade the old maven facade project configuration
 * @param newFacade the new maven facade project configuration
 * @param monitor the progress monitor
 * @return true if the MANIFEST.MF needs to be regenerated
 */
protected boolean needsNewManifest(IFile manifest, IMavenProjectFacade oldFacade, IMavenProjectFacade newFacade,
        IProgressMonitor monitor) {

    if (!manifest.exists()) {
        return true;
    }
    //Can't compare to a previous state, so assuming it's unchanged
    //This situation actually occurs during incremental builds, 
    //when called from the buildParticipant
    if (oldFacade == null || oldFacade.getMavenProject() == null) {
        return false;
    }

    MavenProject newProject = newFacade.getMavenProject();
    MavenProject oldProject = oldFacade.getMavenProject();

    //Assume Sets of artifacts are actually ordered
    if (dependenciesChanged(
            oldProject.getArtifacts() == null ? null : new ArrayList<Artifact>(oldProject.getArtifacts()),
            newProject.getArtifacts() == null ? null : new ArrayList<Artifact>(newProject.getArtifacts()))) {
        return true;
    }

    Xpp3Dom oldArchiveConfig = getArchiveConfiguration(oldProject);
    Xpp3Dom newArchiveConfig = getArchiveConfiguration(newProject);

    if (newArchiveConfig != null && !newArchiveConfig.equals(oldArchiveConfig) || oldArchiveConfig != null) {
        return true;
    }

    //Name always not null
    if (!newProject.getName().equals(oldProject.getName())) {
        return true;
    }

    String oldOrganizationName = oldProject.getOrganization() == null ? null
            : oldProject.getOrganization().getName();
    String newOrganizationName = newProject.getOrganization() == null ? null
            : newProject.getOrganization().getName();

    if (newOrganizationName != null && !newOrganizationName.equals(oldOrganizationName)
            || oldOrganizationName != null && newOrganizationName == null) {
        return true;
    }
    return false;
}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project/*from ww  w . ja  va  2s. co  m*/
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

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

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != 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.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:se.natusoft.tools.codelicmgr.MojoUtils.java

License:Open Source License

/**
 * This will take config values that are not specified or specified as blank and
 * look for that information elsewhere in the maven project and if found, update
 * the configuration with that information.
 * <p>//from w  ww  . ja  v a2  s  .  com
 * The reason for this is to minimize duplication of information in the pom. Some
 * of the information managed by CodeLicenseManager is also available as standard
 * information in a pom and is used by site:site to generate documentation.
 *
 * @param project The CLM project config.
 * @param mavenProject Maven project info from pom.
 */
public static ProjectConfig updateConfigFromMavenProject(ProjectConfig project, MavenProject mavenProject) {
    // Project
    if (project == null) { // Will be null if no <project> tag is specified!
        project = new ProjectConfig();
    }
    if (isEmpty(project.getName())) {
        project.setName(getFirstNonEmpty(mavenProject.getName(), mavenProject.getArtifactId()));
    }
    if (isEmpty(project.getDescription())) {
        project.setDescription(mavenProject.getDescription());
    }

    // License
    LicenseConfig licenseConf = project.getLicense();
    if (licenseConf == null) {
        licenseConf = new LicenseConfig();
        project.setLicense(licenseConf);
    }
    if (licenseConf.getType() == null) {
        List<org.apache.maven.model.License> lics = mavenProject.getLicenses();
        if (lics != null && lics.size() >= 1) {
            org.apache.maven.model.License lic = lics.get(0);

            String licName = getLicenseName(lic.getName().replaceAll("-", " "));
            if (licName.trim().length() > 0) {
                licenseConf.setType(licName);
            }

            String licVer = getLicenseVersion(lic.getName().replaceAll("-", " "));
            if (licVer.trim().length() > 0) {
                licenseConf.setVersion(licVer);
            }
        }
    }

    // Copyright
    if (project.getCopyrights().getCopyrights().size() == 0) {
        CopyrightConfig copyrightConf = new CopyrightConfig();
        copyrightConf.setHolder(mavenProject.getOrganization().getName());
        copyrightConf.setYear(mavenProject.getInceptionYear());
        project.getCopyrights().addCopyright(copyrightConf);
    }

    return project;
}