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:aQute.bnd.maven.reporter.plugin.entries.mavenproject.CommonInfoPlugin.java

private ContactAddressDTO extractContactAddress(MavenProject project) {
    if (project.getOrganization() != null && project.getOrganization().getUrl() != null) {
        ContactAddressDTO contact = new ContactAddressDTO();
        contact.address = project.getOrganization().getUrl();
        contact.type = "url";
        return contact;
    } else {//from   w w w  .j a  va2  s . c o m
        return null;
    }
}

From source file:aQute.bnd.maven.reporter.plugin.entries.mavenproject.CommonInfoPlugin.java

private String extractVendor(MavenProject project) {
    if (project.getOrganization() != null) {
        return project.getOrganization().getName();
    } else {//from  w  ww.  j a  va 2  s .c  om
        return null;
    }
}

From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java

License:Apache License

private String getPublisher(MavenProject project) {
    return project.getOrganization() != null ? project.getOrganization().getName()
            : !project.getDevelopers().isEmpty() ? project.getDevelopers().get(0).getName() : null;
}

From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java

License:Apache License

private String getUrl(MavenProject project) {
    return project.getUrl() != null ? project.getUrl()
            : project.getOrganization() != null ? project.getOrganization().getUrl()
                    : !project.getDevelopers().isEmpty() ? project.getDevelopers().get(0).getUrl() : null;
}

From source file:com.sun.enterprise.module.maven.OSGiPackager.java

License:Open Source License

/**
 * Reads information from the POM and the artifact archive to configure
 * the OSGi manifest entries. Returns a new set of entries if the archive
 * does not already have manifest entries, else it uses the existing entries
 * map. If any of the attribute already exists, then
 * it skips its processing honoring user's request. It uses the following
 * rules:/*from w ww  . j a v  a  2  s . co  m*/
 *
 * Bundle-SymbolicName is assumed to be "${groupId}.${artifactId}"
 * Bundle-Version is derived from "${pom.version}"
 * using {@link VersionTranslator#MavenToOSGi(String)}
 * Bundle-Description is assumed to be "${pom.description}".
 * Bundle-Vendor is assumed to be "${pom.organization.name}".
 * Require-Bundle is populated by values read from pom dependencies
 * Note:
 * There is no support for Export-Package yet.
 * It sets Bundle-ManifestVersion as 2 which indicates OSGi r4 bundle.
 *
 * @param pom The Maven project object
 * @param archive The archive that is being built
 * @param classesDirectory output for javac
 * @return Manifest entries
 * @throws java.io.IOException
 */
public Map<String, String> configureOSGiManifest(MavenProject pom, MavenArchiveConfiguration archive,
        File classesDirectory) throws IOException {
    Map<String, String> entries;
    if (archive != null)
        entries = archive.getManifestEntries();
    else
        entries = new HashMap<String, String>();

    if (entries.get(BUNDLE_MANIFESTVERSION) == null) {
        // 2 indicates compliance with r4, note: there is no value called 1
        entries.put(BUNDLE_MANIFESTVERSION, "2");
    }

    if (entries.get(BUNDLE_NAME) == null) {
        // Bundle-Name is a human readable localizable name that can contain spaces
        entries.put(BUNDLE_NAME, pom.getName());
    }

    if (entries.get(BUNDLE_SYMBOLICNAME) == null) {
        // OSGi convention is to use reverse domain name for SymbolicName, hence use .
        entries.put(BUNDLE_SYMBOLICNAME, pom.getGroupId() + '.' + pom.getArtifactId());
    }

    if (entries.get(BUNDLE_VERSION) == null) {
        entries.put(BUNDLE_VERSION, VersionTranslator.MavenToOSGi(pom.getVersion()));
    }

    if (entries.get(BUNDLE_DESCRIPTION) == null) {
        if (pom.getDescription() != null)
            entries.put(BUNDLE_DESCRIPTION, pom.getDescription());
    }

    if (entries.get(BUNDLE_VENDOR) == null) {
        if (pom.getOrganization() != null && pom.getOrganization().getName() != null)
            entries.put(BUNDLE_VENDOR, pom.getOrganization().getName());
    }

    // Handle Require-Bundle.
    if (entries.get(REQUIRE_BUNDLE) == null) {
        String requiredBundles = generateRequireBundleHeader(discoverRequiredBundles(pom));
        if (requiredBundles.length() > 0) {
            entries.put(REQUIRE_BUNDLE, requiredBundles);
        }
    }

    // Handle Export-Package
    if (entries.get(EXPORT_PACKAGE) == null) {
        List<ExportedPackage> packages = discoverPackages(classesDirectory);

        // don't use version until we resolve split package issues in GF
        String exportPackages = generateExportPackageHeader(packages, null);
        if (exportPackages.length() > 0) {
            entries.put(EXPORT_PACKAGE, exportPackages);
        }
    }
    return entries;
}

From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java

private void dump(DependencyNode current, PrintStream out) throws MojoExecutionException, MojoFailureException {
    String artifactId = current.getArtifact().getArtifactId();
    boolean hasClassifier = (current.getArtifact().getClassifier() != null);
    if ((artifactId.startsWith("jsaga-") || artifactId.startsWith("saga-")) && !hasClassifier) {
        MavenProject module = this.getMavenProject(current.getArtifact());
        if (module != null) {
            // Filter does NOT work
            //                AndArtifactFilter scopeFilter = new AndArtifactFilter();
            //                scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE));
            //                scopeFilter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME));
            try {
                current = dependencyTreeBuilder.buildDependencyTree(module, localRepository, factory,
                        artifactMetadataSource, null, collector);
            } catch (DependencyTreeBuilderException e) {
                throw new MojoExecutionException("Unable to build dependency tree", e);
            }//from  w  w  w.j av a  2s.  c o m
        }
    }

    // dump (part 1)
    indent(current, out);
    out.print("<artifact");

    Artifact artifact = current.getArtifact();
    addAttribute(out, "id", artifact.getArtifactId());
    addAttribute(out, "group", artifact.getGroupId());
    // Get version from HashMap
    String v = includedArtifacts.get(artifact.getArtifactId());
    if (v != null) {
        artifact.setVersion(v);
    }
    addAttribute(out, "version", artifact.getVersion());
    addAttribute(out, "type", artifact.getType());
    addAttribute(out, "scope", artifact.getScope());
    addAttribute(out, "classifier", artifact.getClassifier());
    try {
        addAttribute(out, "file", this.getJarFile(artifact).toString());
    } catch (Exception e) {
        getLog().debug(artifact.getArtifactId() + "Could not find JAR");
    }

    MavenProject proj = this.getMavenProject(artifact);
    if (proj != null) {
        if (!proj.getName().startsWith("Unnamed - ")) {
            addAttribute(out, "name", proj.getName());
        }
        addAttribute(out, "description", proj.getDescription());
        addAttribute(out, "url", proj.getUrl());
        if (proj.getOrganization() != null) {
            addAttribute(out, "organization", proj.getOrganization().getName());
            addAttribute(out, "organizationUrl", proj.getOrganization().getUrl());
        }
        if (proj.getLicenses().size() > 0) {
            License license = (License) proj.getLicenses().get(0);
            addAttribute(out, "license", license.getName());
            addAttribute(out, "licenseUrl", license.getUrl());
        }
    }

    out.println(">");

    // recurse
    for (Iterator it = current.getChildren().iterator(); it.hasNext();) {
        DependencyNode child = (DependencyNode) it.next();
        // filter dependencies with scope "test", except those with classifier "tests" (i.e. adaptor integration tests)
        if ("test".equals(child.getArtifact().getScope())
                && !"tests".equals(child.getArtifact().getClassifier())) {
            Artifact c = child.getArtifact();
            getLog().debug(artifact.getArtifactId() + ": ignoring dependency " + c.getGroupId() + ":"
                    + c.getArtifactId());
        } else {
            this.dump(child, out);
        }
    }

    // dump (part 2)
    indent(current, out);
    out.println("</artifact>");
}

From source file:net.dynamic_tools.maven.plugin.javascript.util.JavaScriptArchiver.java

License:Apache License

public void createDefaultManifest(MavenProject project)
        throws ManifestException, IOException, ArchiverException {
    Manifest manifest = new Manifest();
    Manifest.Attribute attr = new Manifest.Attribute("Created-By", "Apache Maven");
    manifest.addConfiguredAttribute(attr);
    attr = new Manifest.Attribute("Implementation-Title", project.getName());
    manifest.addConfiguredAttribute(attr);
    attr = new Manifest.Attribute("Implementation-Version", project.getVersion());
    manifest.addConfiguredAttribute(attr);
    attr = new Manifest.Attribute("Implementation-Vendor-Id", project.getGroupId());
    manifest.addConfiguredAttribute(attr);
    if (project.getOrganization() != null) {
        String vendor = project.getOrganization().getName();
        attr = new Manifest.Attribute("Implementation-Vendor", vendor);
        manifest.addConfiguredAttribute(attr);
    }/*from   w w  w . j a  v a2s . c  o  m*/
    attr = new Manifest.Attribute("Built-By", System.getProperty("user.name"));
    manifest.addConfiguredAttribute(attr);

    File mf = File.createTempFile("maven", ".mf");
    mf.deleteOnExit();
    PrintWriter writer = new PrintWriter(new FileWriter(mf));
    manifest.write(writer);
    writer.close();
    setManifest(mf);
}

From source file:npanday.assembler.impl.AssemblerContextImpl.java

License:Apache License

public AssemblyInfo getAssemblyInfo(MavenProject mavenProject) {
    String basedir = mavenProject.getBasedir().toString();
    AssemblyInfo assemblyInfo = new AssemblyInfo();
    String description = (mavenProject.getDescription() != null) ? mavenProject.getDescription() : "";
    String version = (mavenProject.getVersion() != null) ? mavenProject.getVersion() : "";
    String name = mavenProject.getName();
    Organization org = mavenProject.getOrganization();
    String company = (org != null) ? org.getName() : "";
    String copyright = "";
    String informationalVersion = "";
    String configuration = "";

    File file = new File(basedir + "/COPYRIGHT.txt");
    if (file.exists()) {
        logger.debug("NPANDAY-020-000: Found Copyright: " + file.getAbsolutePath());
        FileInputStream fis = null;
        try {/*from   ww  w.jav  a 2  s . co m*/
            fis = new FileInputStream(file);
            copyright = IOUtil.toString(fis).replace("\r", " ").replace("\n", " ").replace("\"", "'");
        } catch (IOException e) {
            logger.info("NPANDAY-020-001: Could not get copyright: File = " + file.getAbsolutePath(), e);
        } finally {
            if (fis != null) {
                IOUtil.close(fis);
            }
        }
    }
    informationalVersion = version;
    if (version.contains("-")) {
        version = version.split("-")[0];
    }
    assemblyInfo.setCompany(company);
    assemblyInfo.setCopyright(copyright);
    assemblyInfo.setCulture("");
    assemblyInfo.setDescription(description);
    assemblyInfo.setProduct(company + "-" + name);
    assemblyInfo.setTitle(name);
    assemblyInfo.setTrademark("");
    assemblyInfo.setInformationalVersion(informationalVersion);
    assemblyInfo.setVersion(version);
    assemblyInfo.setConfiguration(configuration);

    return assemblyInfo;
}

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

License:Apache License

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

    String bsn;/*  ww w.j  a v a  2 s.c om*/
    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.fluidity.foundation.impl.BundleJarManifest.java

License:Apache License

public SecurityPolicy processManifest(final MavenProject project, final Attributes attributes,
        final SecurityPolicy policy, final Logger log, final Dependencies dependencies)
        throws MojoExecutionException {
    dependencies.attribute(BUNDLE_CLASSPATH, ",");

    addEntry(attributes, BUNDLE_MANIFESTVERSION, "2");
    addEntry(attributes, BUNDLE_NAME, project::getName);
    addEntry(attributes, BUNDLE_SYMBOLICNAME, project::getArtifactId);
    addEntry(attributes, BUNDLE_VERSION, project::getVersion);
    addEntry(attributes, BUNDLE_DESCRIPTION, project::getDescription);
    addEntry(attributes, BUNDLE_DOCURL, project::getUrl);
    addEntry(attributes, BUNDLE_VENDOR, () -> {
        return project.getOrganization().getName();
    });//from w ww  .ja  v  a 2 s .c  om
    addEntry(attributes, BUNDLE_COPYRIGHT, () -> {
        final String year = project.getInceptionYear();
        return year == null ? null
                : String.format("Copyright %s (c) %s. All rights reserved.",
                        project.getOrganization().getName(), year);
    });
    addEntry(attributes, REQUIRE_CAPABILITY, () -> {

        // https://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
        final String[] version = System.getProperty("java.version").split("\\.");
        return String.format("osgi.ee;filter:=(&(osgi.ee=JavaSE)(version>=%s.%s))", version[0], version[1]);
    });

    final String version = attributes.getValue(BUNDLE_VERSION);

    if (version != null) {
        attributes.putValue(BUNDLE_VERSION, verify(version));
    } else {
        addEntry(attributes, BUNDLE_VERSION, DEFAULT_BUNDLE_VERSION);
    }

    final RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
    final List<String> prefixes = Collections.singletonList("project.");

    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    interpolator.addValueSource(new PrefixedPropertiesValueSource(prefixes, project.getProperties(), true));
    interpolator.addValueSource(new PrefixedObjectValueSource(prefixes, project.getModel(), true));

    final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(prefixes, true);

    interpolator.setCacheAnswers(true);
    interpolator.setReusePatterns(true);

    interpolator.addPostProcessor((ignored, value) -> verify((String) value));

    try {
        interpolateHeaders(attributes, interpolator, interceptor, EXPORT_PACKAGE, IMPORT_PACKAGE,
                DYNAMICIMPORT_PACKAGE, FRAGMENT_HOST, REQUIRE_BUNDLE, BUNDLE_NATIVECODE);
    } catch (final InterpolationException e) {
        throw new IllegalStateException(e);
    }

    final Collection<Artifact> artifacts = dependencies.compiler();

    // if embedding project dependencies, see if Fluid Tools composition is included and if so, add a bundle activator to bootstrap the system.
    if (!artifacts.isEmpty()) {
        try {

            // create a class loader that sees the project's compile-time dependencies
            final Set<URL> urls = new HashSet<>();

            final String skippedId = project.getArtifact().getId();
            for (final Artifact dependency : artifacts) {

                // we don't need the project artifact and don't want to prevent the caller from overwriting it by locking the file...
                if (!skippedId.equals(dependency.getId())) {
                    urls.add(dependency.getFile().toURI().toURL());
                }
            }

            final Method method = Methods.get(BootstrapDiscovery.class, BootstrapDiscovery::activator)[0];

            urls.add((Archives.containing(BootstrapDiscovery.class)));
            urls.add((Archives.containing(BootstrapDiscoveryImpl.class)));
            urls.add((Archives.containing(ComponentContainer.class)));

            final String activator = isolate(null, urls, BootstrapDiscoveryImpl.class, method);

            if (activator != null) {
                addEntry(attributes, BUNDLE_ACTIVATOR, activator);
            }

            if (log.active()) {
                final String value = attributes.getValue(BUNDLE_ACTIVATOR);
                log.detail("Bundle activator: %s", value == null ? "none"
                        : value.equals(BundleBootstrap.class.getName()) ? "built in" : value);
            }
        } catch (final ClassNotFoundException e) {
            // that's OK
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }
    }

    return new OsgiLocalPermissions(policy, artifacts, attributes.getValue(DYNAMICIMPORT_PACKAGE),
            attributes.getValue(IMPORT_PACKAGE), attributes.getValue(EXPORT_PACKAGE));
}