List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.jboss.maven.plugins.qstools.checkers.ArtifactIdPrefixChecker.java
License:Apache License
@Override public void processProject(MavenProject project, Document doc, Map<String, List<Violation>> results) throws Exception { Rules rules = getConfigurationProvider().getQuickstartsRules(project.getGroupId()); String artifarIdPrefix = rules.getArtifactIdPrefix(); if (!project.getArtifactId().startsWith(artifarIdPrefix)) { Node artifacId = (Node) getxPath().evaluate("/project/artifactId", doc, XPathConstants.NODE); int lineNumber = artifacId == null ? 0 : getLineNumberFromNode(artifacId); String msg = "Project with the following artifactId [%s] isn't doesn't start with [%s]"; addViolation(project.getFile(), results, lineNumber, String.format(msg, project.getArtifactId(), artifarIdPrefix)); }/* w ww. ja v a2s.c om*/ }
From source file:org.jboss.mavenPlugin.buildInfo.AbstractParentMojo.java
License:Open Source License
static String createProjectId(MavenProject project) { return project.getGroupId() + SEPARATOR + project.getArtifactId() + SEPARATOR + project.getVersion(); }
From source file:org.jboss.shrinkwrap.resolver.plugin.DependencyTreeMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { // first, we need to propagate environment settings PropagateExecutionContextMojo mojo = new PropagateExecutionContextMojo(); mojo.setNamespace("maven.execution."); mojo.setSession(session);/*w ww .ja v a2 s.c o m*/ mojo.execute(); // propagate into current environment SecurityActions.addProperties(session.getUserProperties()); MavenProject project = session.getCurrentProject(); // set scope ScopeType[] scopes = ScopeType.values(); if (scope != null && !"".equals(scope)) { scopes = new ScopeType[] { ScopeType.fromScopeType(scope) }; } // get ClassLoader that contains both Maven and plugin class path ClassLoader cls = getCombinedClassLoader(classRealmManager); // skip resolution if no dependencies are in the project (e.g. parent agreggator) MavenResolvedArtifact[] artifacts; if (project.getDependencies() == null || project.getDependencies().size() == 0) { artifacts = new MavenResolvedArtifact[0]; } else { artifacts = Maven.configureResolverViaPlugin(cls).importDependencies(scopes).resolve() .withTransitivity().asResolvedArtifact(); } StringBuilder projectGAV = new StringBuilder(); projectGAV.append(project.getGroupId()).append(":").append(project.getArtifactId()).append(":") .append(project.getPackaging()).append(":").append(project.getVersion()).append("\n"); String dependencyTree = buildDependencyTree(projectGAV, "+- ", artifacts); // write output to file if specified if (outputFile != null) { FileWriter writer = null; try { writer = new FileWriter(outputFile); writer.write(dependencyTree); getLog().info("Dependency tree output was writen into: " + outputFile.getAbsolutePath()); } catch (IOException e) { } finally { try { if (writer != null) { writer.close(); } } catch (IOException e) { } } } // write an output to console else { StringBuilder outputBuffer = new StringBuilder(); outputBuffer.append(OUTPUT_DELIMITER).append("\nShrinkWrap Maven: Dependency Tree\n") .append(OUTPUT_DELIMITER).append("\n").append(dependencyTree).append(OUTPUT_DELIMITER); getLog().info(outputBuffer.toString()); } }
From source file:org.jenkinsci.infra.webhook.checkers.MavenChecker.java
License:Open Source License
private void checkArtifactId(MavenProject project, String forkTo, HashSet<VerificationMessage> hostingIssues) { String artifactId = project.getArtifactId(); if (!StringUtils.isBlank(artifactId)) { if (!artifactId.equalsIgnoreCase(forkTo.replace("-plugin", ""))) { hostingIssues.add(new VerificationMessage(Severity.REQUIRED, "The <artifactId> from the pom.xml (%s) is incorrect, it should be %s (new repository name with -plugin removed)", artifactId, forkTo.replace("-plugin", ""))); }//from w w w. j a v a 2 s.c o m if (artifactId.toLowerCase().contains("jenkins") || artifactId.toLowerCase().contains("hudson")) { hostingIssues.add(new VerificationMessage(Severity.REQUIRED, "The <artifactId> from the pom.xml (%s) MUST not contain \"Jenkins\" or \"Hudson\"", artifactId)); } } else { hostingIssues.add(new VerificationMessage(Severity.REQUIRED, "The pom.xml file does not contain a valid <artifactId> for the project")); } }
From source file:org.jenkinsci.maven.plugins.hpi.AbstractHpiMojo.java
License:Apache License
/** * Builds the webapp for the specified project. * <p>//from w w w . ja va2 s . c o m * Classes, libraries and tld files are copied to * the {@code webappDirectory} during this phase. * * @param project the maven project * @param webappDirectory * @throws java.io.IOException if an error occurred while building the webapp */ public void buildWebapp(MavenProject project, File webappDirectory) throws MojoExecutionException, IOException { getLog().info("Assembling webapp " + project.getArtifactId() + " in " + webappDirectory); File libDirectory = new File(webappDirectory, WEB_INF + "/lib"); File tldDirectory = new File(webappDirectory, WEB_INF + "/tld"); Set<MavenArtifact> artifacts = getProjectArtfacts(); List<String> duplicates = findDuplicates(artifacts); List<File> dependentWarDirectories = new ArrayList<File>(); // List up IDs of Jenkins plugin dependencies Set<String> jenkinsPlugins = new HashSet<String>(); for (MavenArtifact artifact : artifacts) { if (artifact.isPlugin()) jenkinsPlugins.add(artifact.getId()); } OUTER: for (MavenArtifact artifact : artifacts) { if (jenkinsPlugins.contains(artifact.getId())) continue; // plugin dependency need not be WEB-INF/lib if (artifact.getDependencyTrail().size() >= 1 && jenkinsPlugins.contains(artifact.getDependencyTrail().get(1))) continue; // no need to have transitive dependencies through plugins in WEB-INF/lib. // if the dependency goes through jenkins core, we don't need to bundle it in the war // because jenkins-core comes in the <provided> scope, I think this is a bug in Maven that it puts such // dependencies into the artifact list. for (String trail : artifact.getDependencyTrail()) { if (trail.contains(":hudson-core:") || trail.contains(":jenkins-core:")) continue OUTER; } String targetFileName = artifact.getDefaultFinalName(); getLog().debug("Processing: " + targetFileName); if (duplicates.contains(targetFileName)) { getLog().debug("Duplicate found: " + targetFileName); targetFileName = artifact.getGroupId() + "-" + targetFileName; getLog().debug("Renamed to: " + targetFileName); } // TODO: utilise appropriate methods from project builder ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); if (!artifact.isOptional() && filter.include(artifact.artifact)) { String type = artifact.getType(); if ("tld".equals(type)) { copyFileIfModified(artifact.getFile(), new File(tldDirectory, targetFileName)); } else { if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type)) { copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName)); } else { if ("par".equals(type)) { targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar"; getLog().debug("Copying " + artifact.getFile() + " to " + new File(libDirectory, targetFileName)); copyFileIfModified(artifact.getFile(), new File(libDirectory, targetFileName)); } else { if ("war".equals(type)) { dependentWarDirectories.add(unpackWarToTempDirectory(artifact)); } else { getLog().debug("Skipping artifact of type " + type + " for WEB-INF/lib"); } } } } } } if (dependentWarDirectories.size() > 0) { getLog().info("Overlaying " + dependentWarDirectories.size() + " war(s)."); // overlay dependent wars for (Iterator iter = dependentWarDirectories.iterator(); iter.hasNext();) { copyDependentWarContents((File) iter.next(), webappDirectory); } } }
From source file:org.jenkinsci.plugins.maveninvoker.MavenInvokerArchiver.java
License:Apache License
@Override public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { if (!mojo.is("org.apache.maven.plugins", "maven-invoker-plugin", "run") && !mojo.is("org.apache.maven.plugins", "maven-invoker-plugin", "integration-test")) { return true; }//from ww w . jav a2 s . c o m final String buildDirectory = new File(pom.getBuild().getDirectory()).getName(); final PrintStream logger = listener.getLogger(); logger.println("MavenInvokerArchiver"); File[] reports = null; try { // projectsDirectory final File projectsDirectory = mojo.getConfigurationValue("projectsDirectory", File.class); // cloneProjectsTo final File cloneProjectsTo = mojo.getConfigurationValue("cloneProjectsTo", File.class); final File reportsDir = mojo.getConfigurationValue("reportsDirectory", File.class); if (reportsDir != null) { reports = reportsDir.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String s) { return s.startsWith("BUILD"); } }); } if (reports != null) { logger.println("found reports:" + Arrays.asList(reports)); } else { logger.println("no reports found"); return true; } final BuildJobXpp3Reader reader = new BuildJobXpp3Reader(); final MavenInvokerResults mavenInvokerResults = new MavenInvokerResults(); // TODO // saveReports for (File f : reports) { InputStream is = new FileInputStream(f); try { BuildJob buildJob = reader.read(is); MavenInvokerResult mavenInvokerResult = MavenInvokerRecorder.map(buildJob); mavenInvokerResult.mavenModuleName = pom.getArtifactId(); mavenInvokerResults.mavenInvokerResults.add(mavenInvokerResult); } catch (XmlPullParserException e) { e.printStackTrace(listener.fatalError("failed to parse report")); build.setResult(Result.FAILURE); return true; } finally { IOUtils.closeQuietly(is); } } logger.println("Finished parsing Maven Invoker results"); int failedCount = build.execute(new MavenBuildProxy.BuildCallable<Integer, IOException>() { private static final long serialVersionUID = 1L; @Override public Integer call(MavenBuild aBuild) throws IOException, IOException, InterruptedException { if (reportsDir == null) { return 0; } FilePath[] reportsPaths = MavenInvokerRecorder.locateReports(aBuild.getWorkspace(), buildDirectory + "/" + reportsDir.getName() + "/BUILD*.xml"); FilePath backupDirectory = MavenInvokerRecorder.getMavenInvokerReportsDirectory(aBuild); MavenInvokerRecorder.saveReports(backupDirectory, reportsPaths); List<FilePath> allBuildLogs = new ArrayList<FilePath>(); for (MavenInvokerResult mavenInvokerResult : mavenInvokerResults.mavenInvokerResults) { // search build.log files File invokerBuildDir = cloneProjectsTo == null ? projectsDirectory : cloneProjectsTo; File projectDir = new File(invokerBuildDir, mavenInvokerResult.project); FilePath[] buildLogs = null; File parentFile = projectDir.getParentFile(); if (parentFile != null) { buildLogs = MavenInvokerRecorder.locateBuildLogs(aBuild.getWorkspace(), "**/" + parentFile.getName()); } if (buildLogs != null) { allBuildLogs.addAll(Arrays.asList(buildLogs)); } } // backup all build.log MavenInvokerRecorder.saveBuildLogs(backupDirectory, allBuildLogs); InvokerReport invokerReport = new InvokerReport(aBuild, mavenInvokerResults); aBuild.addAction(invokerReport); int failed = invokerReport.getFailedTestCount(); return failed; } }); return true; } catch (ComponentConfigurationException e) { e.printStackTrace(listener.fatalError("failed to find report directory")); build.setResult(Result.FAILURE); return true; } }
From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.AbstractMavenEventHandler.java
License:Open Source License
public Xpp3Dom newElement(@Nonnull String name, @Nullable final MavenProject project) { Xpp3Dom projectElt = new Xpp3Dom(name); if (project == null) { return projectElt; }/*from ww w.ja v a 2 s . c o m*/ projectElt.setAttribute("name", project.getName()); projectElt.setAttribute("groupId", project.getGroupId()); projectElt.setAttribute("artifactId", project.getArtifactId()); projectElt.setAttribute("version", project.getVersion()); projectElt.setAttribute("packaging", project.getPackaging()); if (project.getBasedir() != null) { try { projectElt.setAttribute("baseDir", project.getBasedir().getCanonicalPath()); } catch (IOException e) { throw new RuntimeIOException(e); } } if (project.getFile() != null) { File projectFile = project.getFile(); String absolutePath; try { absolutePath = projectFile.getCanonicalPath(); } catch (IOException e) { throw new RuntimeIOException(e); } if (absolutePath.endsWith(File.separator + "pom.xml") || absolutePath.endsWith(File.separator + ".flattened-pom.xml")) { // JENKINS-43616: flatten-maven-plugin replaces the original pom as artifact with a .flattened-pom.xml // no tweak } else if (absolutePath.endsWith(File.separator + "dependency-reduced-pom.xml")) { // JENKINS-42302: maven-shade-plugin creates a temporary project file dependency-reduced-pom.xml // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + "dependency-reduced-pom.xml", File.separator + "pom.xml"); } else if (absolutePath.endsWith(File.separator + ".git-versioned-pom.xml")) { // JENKINS-56666 maven-git-versioning-extension causes warnings due to temporary pom.xml file name '.git-versioned-pom.xml' // https://github.com/qoomon/maven-git-versioning-extension/blob/v4.1.0/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java#L39 // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + ".git-versioned-pom.xml", File.separator + "pom.xml"); } else { String flattenedPomFilename = getMavenFlattenPluginFlattenedPomFilename(project); if (flattenedPomFilename == null) { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } else { if (absolutePath.endsWith(File.separator + flattenedPomFilename)) { absolutePath = absolutePath.replace(File.separator + flattenedPomFilename, File.separator + "pom.xml"); } else { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } } } projectElt.setAttribute("file", absolutePath); } Build build = project.getBuild(); if (build != null) { Xpp3Dom buildElt = new Xpp3Dom("build"); projectElt.addChild(buildElt); if (build.getOutputDirectory() != null) { buildElt.setAttribute("directory", build.getDirectory()); } if (build.getSourceDirectory() != null) { buildElt.setAttribute("sourceDirectory", build.getSourceDirectory()); } } return projectElt; }
From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.ProjectStartedExecutionHandler.java
License:Open Source License
@Override protected void addDetails(@Nonnull ExecutionEvent executionEvent, @Nonnull Xpp3Dom root) { super.addDetails(executionEvent, root); MavenProject parentProject = executionEvent.getProject().getParent(); if (parentProject == null) { // nothing to do } else {// ww w . j ava 2 s . co m Xpp3Dom parentProjectElt = new Xpp3Dom("parentProject"); root.addChild(parentProjectElt); parentProjectElt.setAttribute("name", parentProject.getName()); parentProjectElt.setAttribute("groupId", parentProject.getGroupId()); parentProjectElt.setAttribute("artifactId", parentProject.getArtifactId()); parentProjectElt.setAttribute("version", parentProject.getVersion()); } }
From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java
License:Apache License
private void initModule(MavenProject project) { if (project == null) { logger.warn("Skipping Artifactory Build-Info module initialization: Null project."); return;//from w w w .j a v a 2 s .c o m } ModuleBuilder module = new ModuleBuilder(); module.id(getModuleIdString(project.getGroupId(), project.getArtifactId(), project.getVersion())); module.properties(project.getProperties()); currentModule.set(module); currentModuleArtifacts.set(Collections.synchronizedSet(new HashSet<Artifact>())); currentModuleDependencies.set(Collections.synchronizedSet(new HashSet<Artifact>())); }
From source file:org.jfrog.jade.plugins.common.naming.ProjectNameProviderImpl.java
License:Apache License
public String getProjectName(MavenProject project) { String artifactId = project.getArtifactId(); String groupId = project.getGroupId(); return getProjectName(groupId, artifactId); }