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

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

Introduction

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

Prototype

public String getUrl() 

Source Link

Usage

From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java

private Dependency mapDependency(DependencyNode node,
        Map<ComponentId, Map.Entry<MavenProject, String[]>> projectLookup) {
    Dependency.Builder builder = new Dependency.Builder();
    Artifact artifact = node.getArtifact();
    ComponentId artifactId = ComponentId.create(artifact);
    Map.Entry<MavenProject, String[]> projectLicensesPair = projectLookup.get(artifactId);

    // try fallback to artifact baseVersion, (for example because a snapshot is locked )
    if (projectLicensesPair == null) {
        projectLicensesPair = projectLookup.get(ComponentId.createFallback(artifact));
    }/* w  w w  .  ja  v  a  2s. c om*/

    if (projectLicensesPair == null) {
        getLog().error("Something weird happened: no Project found for artifact: " + artifactId);
        return null;
    }

    MavenProject project = projectLicensesPair.getKey();
    String[] licensesArr = projectLicensesPair.getValue();

    builder.setName(project.getName()).setDescription(project.getDescription())
            .setKey("mvn:" + project.getGroupId() + ':' + project.getArtifactId())
            .addVersion(project.getVersion()).setHomepageUrl(project.getUrl());
    if (isPrivateComponent(project)) {
        builder.setPrivate(true);
    }

    try {
        File file = artifact.getFile();
        if (file != null) {
            builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(file));
        } else {
            Artifact af = findProjectArtifact(artifact);
            if (af != null && af.getFile() != null) {
                builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(af.getFile()));
            } else {
                getLog().warn(
                        "Could not generate checksum - no file specified: " + ComponentId.create(artifact));
            }
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        getLog().warn("Could not generate checksum: " + e.getMessage());
    }

    if (licensesArr != null
            && (licensesArr.length != 1 || !LicenseMap.UNKNOWN_LICENSE_MESSAGE.equals(licensesArr[0]))) {
        for (String license : licensesArr) {
            builder.addLicense(license);
        }
    }

    for (DependencyNode childNode : node.getChildren()) {
        Dependency dep = mapDependency(childNode, projectLookup);
        if (dep != null) {
            builder.addDependency(dep);
        }
    }

    return builder.buildDependency();
}

From source file:de.saumya.mojo.gem.GemspecWriter.java

@SuppressWarnings("unchecked")
GemspecWriter(final File gemspec, final MavenProject project, final GemArtifact artifact) throws IOException {
    this.latestModified = project.getFile() == null ? 0 : project.getFile().lastModified();
    this.gemspec = gemspec;
    this.gemspec.getParentFile().mkdirs();
    this.writer = new FileWriter(gemspec);
    this.project = project;

    append("Gem::Specification.new do |s|");
    append("name", artifact.getGemName());
    append("version", gemVersion(project.getVersion()));
    append();//from   w ww.  jav a  2s . c o  m
    append("summary", project.getName());
    append("description", project.getDescription());
    append("homepage", project.getUrl());
    append();

    for (final Developer developer : (List<Developer>) project.getDevelopers()) {
        appendAuthor(developer.getName(), developer.getEmail());
    }
    for (final Contributor contributor : (List<Contributor>) project.getContributors()) {
        appendAuthor(contributor.getName(), contributor.getEmail());
    }
    append();

    for (final License license : (List<License>) project.getLicenses()) {
        appendLicense(license.getUrl(), license.getName());
    }
}

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);
            }/*ww  w  .j ava 2  s.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:io.fabric8.maven.HelmMojo.java

License:Apache License

protected Chart createChart() {
    Chart answer = new Chart();
    answer.setName(chartName);/*from w w  w .  j  a va  2 s  . c  o  m*/
    MavenProject project = getProject();
    if (project != null) {
        answer.setVersion(project.getVersion());
        answer.setDescription(project.getDescription());
        answer.setHome(project.getUrl());
        List<Developer> developers = project.getDevelopers();
        if (developers != null) {
            List<String> maintainers = new ArrayList<>();
            for (Developer developer : developers) {
                String email = developer.getEmail();
                String name = developer.getName();
                String text = Strings.defaultIfEmpty(name, "");
                if (Strings.isNotBlank(email)) {
                    if (Strings.isNotBlank(text)) {
                        text = text + " <" + email + ">";
                    } else {
                        text = email;
                    }
                }
                if (Strings.isNotBlank(text)) {
                    maintainers.add(text);
                }
            }
            answer.setMaintainers(maintainers);
        }
    }
    return answer;
}

From source file:io.sarl.maven.docs.AbstractDocumentationMojo.java

License:Apache License

private Properties createProjectProperties() {
    final Properties props = new Properties();
    final MavenProject prj = this.session.getCurrentProject();
    props.put("project.groupId", prj.getGroupId()); //$NON-NLS-1$
    props.put("project.artifactId", prj.getArtifactId()); //$NON-NLS-1$
    props.put("project.basedir", prj.getBasedir()); //$NON-NLS-1$
    props.put("project.description", prj.getDescription()); //$NON-NLS-1$
    props.put("project.id", prj.getId()); //$NON-NLS-1$
    props.put("project.inceptionYear", prj.getInceptionYear()); //$NON-NLS-1$
    props.put("project.name", prj.getName()); //$NON-NLS-1$
    props.put("project.version", prj.getVersion()); //$NON-NLS-1$
    props.put("project.url", prj.getUrl()); //$NON-NLS-1$
    props.put("project.encoding", this.encoding); //$NON-NLS-1$
    return props;
}

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

License:Apache License

/**
 * Returns the model of the {@link org.apache.maven.project.MavenProject} to generate.
 * This is a trimmed down version and contains just the stuff that need to go into the bom.
 *
 * @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}.
 *///from   w  ww . j  a va2 s .  c  om
private static MavenProject toGenerate(MavenProject project, BomConfig config,
        Collection<Dependency> dependencies, Set<Artifact> plugins) {
    MavenProject toGenerate = project.clone();
    toGenerate.setGroupId(project.getGroupId());
    toGenerate.setArtifactId(config.getArtifactId());
    toGenerate.setVersion(project.getVersion());
    toGenerate.setPackaging("pom");
    toGenerate.setName(config.getName());
    toGenerate.setDescription(config.getDescription());

    toGenerate.setUrl(project.getUrl());
    toGenerate.setLicenses(project.getLicenses());
    toGenerate.setScm(project.getScm());
    toGenerate.setDevelopers(project.getDevelopers());

    toGenerate.getModel().setDependencyManagement(new DependencyManagement());
    for (Dependency dependency : dependencies) {
        toGenerate.getDependencyManagement().addDependency(dependency);
    }

    toGenerate.getModel().setBuild(new Build());
    if (!plugins.isEmpty()) {
        toGenerate.getModel().setBuild(new Build());
        toGenerate.getModel().getBuild().setPluginManagement(new PluginManagement());
        for (Artifact artifact : plugins) {
            toGenerate.getPluginManagement().addPlugin(toPlugin(artifact));
        }
    }

    return toGenerate;
}

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}.
 *///  ww w .j  a v  a 2  s.c o 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:net.sf.sitemapplugin.Sitemap.java

License:Apache License

private static void extractItems(final MavenProject project, final List<MenuItem> items,
        final WebSitemapGenerator generator, final ChangeFreq changeFreq) throws MalformedURLException {
    if (items == null || items.isEmpty()) {
        return;// w w w  .  ja  v a 2s .  com
    }

    for (final MenuItem item : items) {
        final Options options = new Options(project.getUrl() + relativePath(item.getHref()));
        options.lastMod(new Date());
        options.changeFreq(changeFreq);
        generator.addUrl(options.build());
        extractItems(project, item.getItems(), generator, changeFreq);
    }
}

From source file:net.ubos.tools.pacmanpkgmavenplugin.PacmanPkgMavenPlugin.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w  w  .jav a2s .com*/
 * 
 * @throws MojoExecutionException
 */
@Override
public void execute() throws MojoExecutionException {
    MavenProject project = (MavenProject) getPluginContext().get("project");
    String packaging = project.getPackaging();

    if (!"jar".equals(packaging) && !"ear".equals(packaging) && !"war".equals(packaging)) {
        return;
    }

    getLog().info("Generating PKGBUILD @ " + project.getName());

    // pull stuff out of MavenProject
    String artifactId = project.getArtifactId();
    String version = project.getVersion();
    String url = project.getUrl();
    String description = project.getDescription();
    Set<Artifact> dependencies = project.getDependencyArtifacts();
    File artifactFile = project.getArtifact().getFile();

    if (artifactFile == null || !artifactFile.exists()) {
        throw new MojoExecutionException("pacmanpkg must be executed as part of a build, not standalone,"
                + " otherwise it can't find the main JAR file");
    }
    // translate to PKGBUILD fields
    String pkgname = artifactId;
    String pkgver = version.replaceAll("-SNAPSHOT", "a"); // alpha
    String pkgdesc = "A Java package available on UBOS";
    if (description != null) {
        if (description.length() > 64) {
            pkgdesc = description.substring(0, 64) + "...";
        } else {
            pkgdesc = description;
        }
    }

    ArrayList<String> depends = new ArrayList<>(dependencies.size());
    for (Artifact a : dependencies) {
        if (!"test".equals(a.getScope())) {
            depends.add(a.getArtifactId());
        }
    }
    // write to PKGBUILD
    try {
        File baseDir = project.getBasedir();
        File pkgBuild = new File(baseDir, "target/PKGBUILD");
        PrintWriter out = new PrintWriter(pkgBuild);

        getLog().debug("Writing PKGBUILD to " + pkgBuild.getAbsolutePath());

        out.println("#");
        out.println(" * Automatically generated by pacman-pkg-maven-plugin; do not modify.");
        out.println("#");

        out.println();

        out.println("pkgname=" + pkgname);
        out.println("pkgver=" + pkgver);
        out.println("pkgrel=" + pkgrel);
        out.println("pkgdesc='" + pkgdesc + "'");
        out.println("arch=('any')");
        out.println("url='" + url + "'");
        out.println("license=('" + license + "')");

        out.print("depends=(");
        String sep = "";
        for (String d : depends) {
            out.print(sep);
            sep = ",";
            out.print("'");
            out.print(d);
            out.print("'");
        }
        out.println(")");

        out.println();

        out.println("package() (");
        out.println("   mkdir -p ${pkgdir}/usr/share/java");
        out.println("   install -m644 ${startdir}/" + artifactFile.getName() + " ${pkgdir}/usr/share/java/");
        out.println(")");

        out.close();

    } catch (IOException ex) {
        throw new MojoExecutionException("Failed to write target/PKGBUILD", ex);
    }
}

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//from   w ww .j a va  2s  .  com
 */
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;
}