List of usage examples for org.apache.maven.project MavenProject getUrl
public String getUrl()
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//from ww w .ja v a 2s.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.project.Project.java
License:Apache License
public Project(MavenProject project, String location, File artifactPath) { mavenProject = project;/*from w w w. ja v a 2s. c o 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.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
public static String getArtifactName(MavenProject project) { StringBuilder sb = new StringBuilder(); if (project.getName().startsWith("Unnamed -")) { // as in Maven 3, let's use the artifact id sb.append(project.getArtifactId()); } else {//from w w w . jav a 2s . co m sb.append(project.getName()); } sb.append(" ("); sb.append(project.getGroupId()); sb.append(":"); sb.append(project.getArtifactId()); sb.append(":"); sb.append(project.getVersion()); sb.append(" - "); String url = project.getUrl(); sb.append(url == null ? "no url defined" : url); sb.append(")"); return sb.toString(); }
From source file:org.eclipse.m2e.core.ui.internal.actions.OpenUrlAction.java
License:Open Source License
private static String getUrl(String actionId, MavenProject mavenProject) { String url = null;// w w w . ja v a 2s . c o m if (ID_PROJECT.equals(actionId)) { url = mavenProject.getUrl(); if (url == null) { openDialog(Messages.OpenUrlAction_error_no_url); } } else if (ID_ISSUES.equals(actionId)) { IssueManagement issueManagement = mavenProject.getIssueManagement(); if (issueManagement != null) { url = issueManagement.getUrl(); } if (url == null) { openDialog(Messages.OpenUrlAction_error_no_issues); } } else if (ID_SCM.equals(actionId)) { Scm scm = mavenProject.getScm(); if (scm != null) { url = scm.getUrl(); } if (url == null) { openDialog(Messages.OpenUrlAction_error_no_scm); } } else if (ID_CI.equals(actionId)) { CiManagement ciManagement = mavenProject.getCiManagement(); if (ciManagement != null) { url = ciManagement.getUrl(); } if (url == null) { openDialog(Messages.OpenUrlAction_error_no_ci); } } return url; }
From source file:org.heneveld.maven.license_audit.util.MavenUtil.java
/** If the URL is not declared on the project's original model, * take the parent's declared URL; NOT the inference done by maven * (which appends the child artifactId, often wrongly. */// www. j a v a 2 s . co m public static String getDeclaredUrl(MavenProject p) { String result = p.getUrl(); if (result == null) return null; if (p.getOriginalModel() == null || p.getOriginalModel().getUrl() != null) return result; // if url is inferred, take the parent's url instead MavenProject pp = p.getParent(); if (pp == null) return result; return getDeclaredUrl(pp); }
From source file:org.kaazing.license.maven.plugin.VerifyNotice.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { Set<MavenProject> dependenciesMavenProject = new TreeSet<MavenProject>(new MavenProjectComparator()); loadAllDepenencyProject(dependenciesMavenProject, getProject()); List<MavenProject> dependenciesMavenProjectList = new ArrayList<MavenProject>(dependenciesMavenProject); StringBuilder sb = new StringBuilder(); for (MavenProject dependencyProj : dependenciesMavenProjectList) { String version = dependencyProj.getVersion(); String[] versions = version.split("\\."); // attempt to just get major minor version of dependency if (versions.length == 1) { version = versions[0];// w w w . j a v a2s . co m } else if (versions.length >= 2) { version = versions[0] + "." + versions[1]; } sb.append(String.format("This product depends on %s %s\n\n", dependencyProj.getName(), version)); // add license to notice List<License> licenses = getLicenses(dependencyProj); if (licenses.size() > 0) { // if have license add them for (License license : licenses) { sb.append(formatLicense(license.getUrl(), license.getName())); } } else { // else attempt adding license from hints ProjectDescription description = getProjectDescriptionFromHints(dependencyProj); if (description != null) { sb.append(formatLicense(description.getLicenseUrl(), description.getLicenseName())); } else if (!strict) { sb.append("\tLicense is not included in maven artifact, look at homepage for license\t\n"); } else { throw new MojoFailureException("Artifact " + dependencyProj.getArtifactId() + " with name \"" + dependencyProj.getName() + "\"" + " does not have a license in pom, include it in plugin configuration"); } } // add homepage to notice String homePage = dependencyProj.getUrl(); if (homePage != null) { sb.append(String.format("\tHomepage:\t%s\n", homePage)); } else { ProjectDescription description = getProjectDescriptionFromHints(dependencyProj); if (description != null) { sb.append(String.format("\tHomepage:\t%s\n", description.getHomePage())); } else if (!strict) { sb.append( "Home page is not included in maven artifact, and thus couldn't be referenced here\n"); } else { throw new MojoFailureException("Artifact " + dependencyProj.getArtifactId() + " does not have a homepage in pom, include it in plugin configuration"); } } // add new line for formatting sb.append("\n"); } if (modifiedCode != null && !modifiedCode.isEmpty()) { Collections.sort(modifiedCode, new ProjectDescriptionComparator()); for (ProjectDescription modifiedCodeInstance : modifiedCode) { sb.append(format("This product contains a modified version of %s %s\n\n", modifiedCodeInstance.getProjectName(), modifiedCodeInstance.getVersion())); sb.append(format("\tLicense:\t%s (%s)\n", modifiedCodeInstance.getLicenseName(), modifiedCodeInstance.getLicenseUrl())); sb.append(format("\tHomepage:\t%s\n\n", modifiedCodeInstance.getHomePage())); } } // If there are dependencies or modified code, write it to the output file if (!(dependenciesMavenProjectList.isEmpty() && (modifiedCode == null || modifiedCode.isEmpty()))) { new File(new File(noticeOutput).getParent()).mkdirs(); try (PrintWriter out = new PrintWriter(noticeOutput)) { out.write(sb.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); throw new MojoFailureException("Failed to save notice to output file ", e); } } // If matching with existing, attempt match if (matchWithExisting) { try { boolean cmp = compareFilesLineByLine(notice, noticeOutput); if (!cmp) { throw new MojoFailureException(notice + " does not equal generated " + noticeOutput); } } catch (IOException e) { e.printStackTrace(); throw new MojoFailureException("Failed to compare notice files", e); } } }
From source file:org.nuxeo.build.swing.tree.ItemProvider.java
License:Open Source License
public String getInfo(Node node) { String id = node.getId().substring(0, node.getId().length() - 1); Collection<Edge> edgesIn = node.getEdgesIn(); String scopes = null;/*from w w w .jav a2 s.c om*/ if (edgesIn != null && !edgesIn.isEmpty()) { scopes = "<br>"; for (Edge edge : edgesIn) { scopes += " <dd>" + edge.in.getArtifact().getArtifactId() + ": <strong><i>" + (edge.scope == null ? "compile" : edge.scope) + "</i></strong></dd><br>"; } // scopes+="</ul>"; } else { scopes = "N/A"; } MavenProject pom = node.getPomIfAlreadyLoaded(); String desc = null; if (pom != null) { desc = "<i>" + pom.getDescription() + "</i>"; String href = pom.getUrl(); String fileRef = null; try { fileRef = node.getFile().toURI().toURL().toExternalForm(); } catch (Exception e) { fileRef = "file:/" + node.getFile().getAbsolutePath(); } desc += "<p><b>Url:</b> " + href + "<br><b>File:</b> <a href=\"" + fileRef + "\">" + node.getFile() + "</a></p>"; } else { desc = "<i><font color=\"light-gray\">Pom not loaded. Enter the artifact to load it.</font></i>"; } return "<html><body><b>Artifact: </b> " + id + "<br><b>Scopes: </b>" + scopes + "<p>" + desc + "</p></body></html>"; }
From source file:org.phpmaven.sitemap.SitemapIndexMojo.java
License:Apache License
private void parseProject(final List<String> urls, final MavenProject project) throws ProjectBuildingException { for (final Plugin plugin : project.getBuild().getPlugins()) { if (plugin.getArtifactId().equals("sitemap-plugin") && plugin.getGroupId().equals("org.phpmaven.sites")) { urls.add(project.getUrl()); }//w w w .j av a2 s. c o m } for (final String module : project.getModules()) { final File moduleFolder = new File(project.getBasedir(), module); final File pomFile = new File(moduleFolder, "pom.xml"); if (pomFile.exists()) { this.parseProject(urls, this.getProjectFromPom(pomFile)); } } }
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); }//from w w w . j av a 2 s . c om } }
From source file:org.sonar.batch.maven.MavenProjectConverter.java
License:Open Source License
/** * For SONAR-3676// w w w .jav a 2 s . com */ private static void convertMavenLinksToProperties(ProjectDefinition definition, MavenProject pom) { setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_HOME_PAGE, pom.getUrl()); Scm scm = pom.getScm(); if (scm == null) { scm = new Scm(); } setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_SOURCES, scm.getUrl()); setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_SOURCES_DEV, scm.getDeveloperConnection()); CiManagement ci = pom.getCiManagement(); if (ci == null) { ci = new CiManagement(); } setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_CI, ci.getUrl()); IssueManagement issues = pom.getIssueManagement(); if (issues == null) { issues = new IssueManagement(); } setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_ISSUE_TRACKER, issues.getUrl()); }