List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:com.github.jrh3k5.flume.mojo.plugin.AbstractFlumePluginMojo.java
License:Apache License
/** * Format the name of a Maven project.// w w w . j av a 2s .c om * * @param mavenProject * The {@link MavenProject} whose name is to be formatted. * @return A formatted identifier of the given {@link MavenProject}. */ protected static String formatIdentifier(MavenProject mavenProject) { return String.format("%s:%s:%s:%s", mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion(), mavenProject.getPackaging()); }
From source file:com.github.spyhunter99.jacoco.report.plugin.JacocoReport.java
License:Apache License
private List<JacocoItem> copyResources(MavenProject project) throws IOException { if (project == null) { return Collections.EMPTY_LIST; }/*from w w w.java 2s .c om*/ List<JacocoItem> outDirs = new ArrayList<>(); if ("pom".equalsIgnoreCase(project.getPackaging())) { for (int k = 0; k < project.getCollectedProjects().size(); k++) { outDirs.addAll(copyResources((MavenProject) project.getCollectedProjects().get(k))); } } else { File moduleBaseDir = project.getBasedir(); File target = new File(moduleBaseDir, "target"); if (target.exists()) { File jacocoUt = new File(moduleBaseDir, "target/site/jacoco-ut/"); //TODO properterize File jacocoIt = new File(moduleBaseDir, "target/site/jacoco-it/"); //TODO properterize JacocoItem item = new JacocoItem(); item.setModuleName(project.getArtifactId()); if (jacocoIt.exists()) { //since all artifacts should have unique names...this should be ok JacocoReportMetric report = new JacocoReportMetric(); report.setReportDir(jacocoIt); report.setMetric(getMetric(new File(jacocoIt, "index.html"))); item.getReportDirs().add(report); File dest = new File( "target/site/jacoco/" + project.getArtifactId() + "/" + jacocoIt.getName()); dest.mkdirs(); org.apache.commons.io.FileUtils.copyDirectory(jacocoIt, dest); } if (jacocoUt.exists()) { //since all artifacts should have unique names...this should be ok JacocoReportMetric report = new JacocoReportMetric(); report.setReportDir(jacocoUt); report.setMetric(getMetric(new File(jacocoUt, "index.html"))); item.getReportDirs().add(report); File dest = new File( "target/site/jacoco/" + project.getArtifactId() + "/" + jacocoUt.getName()); dest.mkdirs(); org.apache.commons.io.FileUtils.copyDirectory(jacocoUt, dest); } outDirs.add(item); } } return outDirs; }
From source file:com.github.zhve.ideaplugin.ArtifactHolder.java
License:Apache License
public List<MavenProject> getProjectsWithPackaging(String packaging) { List<MavenProject> projects = new ArrayList<MavenProject>(); for (MavenProject project : dependencyMap.keySet()) if (project.getPackaging().equals(packaging)) projects.add(project);/* w w w. j av a 2s. c o m*/ return projects; }
From source file:com.github.zhve.ideaplugin.IdeaPluginMojo.java
License:Apache License
protected void doExecute() throws Exception { // prepare//from w w w . jav a 2 s.c o m ArtifactHolder artifactHolder = getArtifactHolder(); VelocityWorker velocityWorker = getVelocityWorker(); VelocityContext context = new VelocityContext(); MavenProject project = getProject(); // fill iml-attributes String buildDirectory = project.getBuild().getDirectory(); String standardBuildDirectory = project.getFile().getParent() + File.separator + "target"; context.put("buildDirectory", buildDirectory.startsWith(standardBuildDirectory) ? standardBuildDirectory : buildDirectory); context.put("context", this); context.put("gaeHome", gaeHome == null ? null : new File(gaeHome).getCanonicalPath()); context.put("MD", "$MODULE_DIR$"); context.put("packagingPom", "pom".equals(project.getPackaging())); context.put("packagingWar", "war".equals(project.getPackaging())); context.put("project", project); // generate iml file createFile(context, velocityWorker.getImlTemplate(), "iml"); // for non execution root just exit if (!getProject().isExecutionRoot()) return; // fill ipr-attributes context.put("M", getLocalRepositoryBasePath()); context.put("assembleModulesIntoJars", assembleModulesIntoJars); context.put("jdkName", jdkName); context.put("jdkLevel", jdkLevel); context.put("wildcardResourcePatterns", Util.escapeXmlAttribute(wildcardResourcePatterns)); List<MavenProject> warProjects = artifactHolder.getProjectsWithPackaging("war"); // check id uniques Set<String> used = new HashSet<String>(); for (MavenProject item : warProjects) if (!used.add(item.getArtifactId())) throw new MojoExecutionException( "Two or more war-packagins projects in reactor have the same artifactId, please make sure that <artifactId> is unique for each war-packagins project."); Collections.sort(warProjects, ProjectComparator.INSTANCE); context.put("warProjects", warProjects); IssueManagement issueManagement = getProject().getIssueManagement(); if (issueManagement != null) { String system = issueManagement.getSystem(); String url = issueManagement.getUrl(); if ("Redmine".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/issues/$0"); } else if ("JIRA".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "[A-Z]+\\-\\d+"); context.put("linkRegexp", url + "/browse/$0"); } else if ("YouTrack".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "[A-Z]+\\-\\d+"); context.put("linkRegexp", url + "/issue/$0"); } else if ("Google Code".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/issues/detail?id=$0"); } else if ("GitHub".equalsIgnoreCase(system)) { context.put("issueNavigationExist", Boolean.TRUE); context.put("issueRegexp", "\\d+"); context.put("linkRegexp", url + "/$0"); } } createFile(context, velocityWorker.getIprTemplate(), "ipr"); // fill iws-attributes context.put("compileInBackground", compileInBackground); context.put("assertNotNull", assertNotNull); context.put("hideEmptyPackages", hideEmptyPackages); context.put("autoscrollToSource", autoscrollToSource); context.put("autoscrollFromSource", autoscrollFromSource); context.put("sortByType", sortByType); context.put("optimizeImportsBeforeCommit", optimizeImportsBeforeCommit); context.put("reformatCodeBeforeCommit", reformatCodeBeforeCommit); context.put("performCodeAnalysisBeforeCommit", performCodeAnalysisBeforeCommit); if (!warProjects.isEmpty()) { // fill war-attributes MavenProject warProject = getDefaultWarProject(warProjects); context.put("warProject", warProject); warProjects.remove(warProject); context.put("otherWarProjects", warProjects); context.put("applicationServerTitle", StringUtils.isEmpty(applicationServerTitle) ? warProject.getArtifactId() : Util.escapeXmlAttribute(applicationServerTitle)); context.put("applicationServerName", gaeHome == null ? applicationServerName : "Google AppEngine Dev"); context.put("applicationServerVersion", applicationServerVersion); context.put("openInBrowser", openInBrowser); context.put("openInBrowserUrl", Util.escapeXmlAttribute(openInBrowserUrl)); context.put("vmParameters", vmParameters == null ? "" : Util.escapeXmlAttribute(vmParameters)); context.put("deploymentContextPath", deploymentContextPath); if (gaeHome != null) { context.put("applicationServerConfigurationType", "GoogleAppEngineDevServer"); context.put("applicationServerFullName", applicationServerFullName == null ? "AppEngine Dev" : applicationServerFullName); } else if ("Tomcat".equals(applicationServerName)) { context.put("applicationServerConfigurationType", "#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory"); context.put("applicationServerFullName", applicationServerFullName == null ? applicationServerName + " " + applicationServerVersion : applicationServerFullName); } else if ("Jetty".equals(applicationServerName)) { context.put("applicationServerConfigurationType", "org.codebrewer.idea.jetty.JettyRunConfigurationType"); context.put("applicationServerFullName", applicationServerFullName == null ? applicationServerName + " " + applicationServerVersion : applicationServerFullName); } else throw new MojoExecutionException("Unknown applicationServerName: " + applicationServerName + ", possible values: Tomcat, Jetty"); } createFile(context, velocityWorker.getIwsTemplate(), "iws"); File idea = new File(project.getBasedir(), ".idea"); if (idea.exists()) { getLog().info(""); getLog().info("Delete Workspace Files:"); getLog().info(""); Util.deleteFileOrDirectory(getLog(), idea); } }
From source file:com.greenpepper.maven.runner.resolver.FileResolver.java
License:Open Source License
/** {@inheritDoc} */ public final File resolve(String value) throws ProjectBuildingException { File projectFile = new File(value); MavenProject mavenProject = embedder.readProject(projectFile); mavenGAV = new ProjectFileResolver.MavenGAV(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion());//w w w . ja v a2s. co m mavenGAV.setPackaging(mavenProject.getPackaging()); return projectFile; }
From source file:com.infosupport.ellison.sonarplugin.ELCheckerSensor.java
License:Open Source License
/** * Look for the project's artifact.// w ww . j a va2 s.co m * This method has been taken from the Sonar <a href="http://docs.codehaus.org/display/SONAR/Artifact+Size+Plugin"> * artifact-size-plugin</a>, whose author are Olivier Gaudin and Waleri Enns. * License: LGPL v3 * * @param pom * the object representing the project's maven configuration * @param fileSystem * the filesystem of the project that is being checked * * @return a file pointing to the artifact path set in the settings (see * {@link ELCheckerSensor#ELCheckerSensor(org.apache.maven.project.MavenProject, * org.sonar.api.config.Settings, ELApplicationCheckerSonarBatchComponent)} * if that has been set, otherwise the artifact as defined by the maven packaging. */ protected File searchArtifactFile(MavenProject pom, ProjectFileSystem fileSystem) { File file = null; if (StringUtils.isNotEmpty(savedArtifactPath)) { file = buildPathFromConfig(fileSystem, savedArtifactPath); } else if (pom != null && pom.getBuild() != null) { String filename = pom.getBuild().getFinalName() + "." + pom.getPackaging(); file = buildPathFromPom(fileSystem, filename); } return file; }
From source file:com.jayway.maven.plugins.android.common.BuildHelper.java
License:Open Source License
/** * @return True if this project constructs an APK as opposed to an AAR or APKLIB. *//*from ww w .j a v a2 s . co m*/ public boolean isAPKBuild(MavenProject project) { return APK.equals(project.getPackaging()); }
From source file:com.jayway.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { log.debug(""); log.debug("ClasspathModifierLifecycleParticipant#afterProjectsRead - start"); log.debug(""); log.debug("CurrentProject=" + session.getCurrentProject()); final List<MavenProject> projects = session.getProjects(); final DependencyResolver dependencyResolver = new DependencyResolver(log, dependencyGraphBuilder); final ArtifactResolverHelper artifactResolverHelper = new ArtifactResolverHelper(artifactResolver, log); for (MavenProject project : projects) { log.debug(""); log.debug("project=" + project.getArtifact()); if (!AndroidExtension.isAndroidPackaging(project.getPackaging())) { continue; // do not modify classpath if not an android project. }/*from w w w. j a v a 2 s . c om*/ final UnpackedLibHelper helper = new UnpackedLibHelper(artifactResolverHelper, project, log); final Set<Artifact> artifacts; // If there is an extension ClassRealm loaded for this project then use that // as the ContextClassLoader so that Wagon extensions can be used to resolves dependencies. final ClassLoader projectClassLoader = (project.getClassRealm() != null) ? project.getClassRealm() : Thread.currentThread().getContextClassLoader(); final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(projectClassLoader); artifacts = dependencyResolver.getProjectDependenciesFor(project, session); } catch (DependencyGraphBuilderException e) { // Nothing to do. The resolution failure will be displayed by the standard resolution mechanism. continue; } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } log.debug("projects deps: : " + artifacts); for (Artifact artifact : artifacts) { final String type = artifact.getType(); if (type.equals(AndroidExtension.AAR)) { // An AAR lib contains a classes jar that needs to be added to the classpath. // Create a placeholder classes.jar and add it to the compile classpath. // It will replaced with the real classes.jar by GenerateSourcesMojo. addClassesToClasspath(helper, project, artifact); // Add jar files in 'libs' into classpath. addLibsJarsToClassPath(helper, project, artifact); } else if (type.equals(AndroidExtension.APK)) { // The only time that an APK will likely be a dependency is when this an an APK test project. // So add a placeholder (we cannot resolve the actual dep pre build) to the compile classpath. // The placeholder will be replaced with the real APK jar later. addClassesToClasspath(helper, project, artifact); } else if (type.equals(AndroidExtension.APKLIB)) { // Add jar files in 'libs' into classpath. addLibsJarsToClassPath(helper, project, artifact); } } } log.debug(""); log.debug("ClasspathModifierLifecycleParticipant#afterProjectsRead - finish"); }
From source file:com.liferay.ide.maven.core.BundleProjectConfigurator.java
License:Open Source License
private boolean isMavenBundlePlugin(IProject project) { final NullProgressMonitor monitor = new NullProgressMonitor(); final IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor); if (facade != null) { try {/*from ww w. j a va 2s .co m*/ final MavenProject mavenProject = facade.getMavenProject(new NullProgressMonitor()); if (mavenProject != null && "bundle".equals(mavenProject.getPackaging())) { final Plugin mavenBundlePlugin = MavenUtil.getPlugin(facade, ILiferayMavenConstants.MAVEN_BUNDLE_PLUGIN_KEY, monitor); if (mavenBundlePlugin != null) { return true; } } else if (mavenProject != null && "jar".equals(mavenProject.getPackaging())) { final Plugin bndMavenPlugin = MavenUtil.getPlugin(facade, ILiferayMavenConstants.BND_MAVEN_PLUGIN_KEY, monitor); if (bndMavenPlugin != null) { return true; } } } catch (CoreException e) { } } return false; }
From source file:com.liferay.ide.maven.core.FacetedMavenProject.java
License:Open Source License
public Collection<IFile> getOutputs(boolean buildIfNeeded, IProgressMonitor monitor) throws CoreException { final Collection<IFile> outputs = new HashSet<IFile>(); if (buildIfNeeded) { this.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); new MavenProjectBuilder(this.getProject()).runMavenGoal(getProject(), "package", monitor); final IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(getProject(), monitor); final MavenProject mavenProject = projectFacade.getMavenProject(monitor); final String targetFolder = mavenProject.getBuild().getDirectory(); final String targetWar = mavenProject.getBuild().getFinalName() + "." + mavenProject.getPackaging(); final IFile output = getProject().getFile(new Path(targetFolder).append(targetWar)); if (output.exists()) { outputs.add(output);/* w w w .j a v a 2 s. com*/ } } return outputs; }