List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:com.liferay.ide.maven.core.MavenProjectRemoteServerPublisher.java
License:Open Source License
public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException { IPath retval = null;/*from w ww. j ava 2s . c o m*/ if (runMavenGoal(getProject(), 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(); retval = new Path(targetFolder).append(targetWar); } return retval; }
From source file:com.napramirez.relief.maven.plugins.GenerateConfigurationMojo.java
License:Apache License
public void execute() throws MojoExecutionException { try {/*from w w w . j a va2 s. c om*/ JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Configuration configuration = new Configuration(); List<Project> projects = new ArrayList<Project>(); for (MavenProject mavenProject : reactorProjects) { if (!MAVEN_PROJECT_PACKAGING_POM.equals(mavenProject.getPackaging())) { Project project = new Project(); project.setName(mavenProject.getName()); Jre jre = new Jre(); String jrePath = System.getenv(ENV_VAR_JAVA_HOME); if (jrePath != null && !jrePath.trim().isEmpty()) { jre.setPath(jrePath); } project.setJre(jre); project.setBuildDirectory(mavenProject.getBuild().getOutputDirectory()); project.setSources(mavenProject.getCompileSourceRoots()); Library library = new Library(); library.setFullPath(mavenProject.getCompileClasspathElements()); project.setLibrary(library); projects.add(project); } } configuration.setProjects(projects); if (!outputDirectory.exists() || !outputDirectory.isDirectory()) { if (!outputDirectory.mkdirs()) { throw new IOException("Failed to create directory " + outputDirectory.getAbsolutePath()); } } File outputFile = new File(outputDirectory, outputFilename); marshaller.marshal(configuration, outputFile); getLog().info("Successfully generated configuration file " + outputFilename); } catch (JAXBException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectInfoProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) { // finite set of project properties we expose final Map<String, String> props = new LinkedHashMap<String, String>(65); props.put("project.id", project.getId()); props.put("project.groupId", project.getGroupId()); props.put("project.artifactId", project.getArtifactId()); props.put("project.version", project.getVersion()); props.put("project.name", project.getName()); props.put("project.description", project.getDescription()); props.put("project.modelVersion", project.getModelVersion()); props.put("project.inceptionYear", project.getInceptionYear()); props.put("project.packaging", project.getPackaging()); props.put("project.url", project.getUrl()); final MavenProject parent = project.getParent(); if (parent != null) { props.put("project.parent.id", parent.getId()); props.put("project.parent.groupId", parent.getGroupId()); props.put("project.parent.artifactId", parent.getArtifactId()); props.put("project.parent.version", parent.getVersion()); props.put("project.parent.name", parent.getName()); props.put("project.parent.description", parent.getDescription()); props.put("project.parent.modelVersion", parent.getModelVersion()); props.put("project.parent.inceptionYear", parent.getInceptionYear()); props.put("project.parent.packaging", parent.getPackaging()); props.put("project.parent.url", parent.getUrl()); }/* ww w . ja v a 2 s . co m*/ // properties the user wants Map<String, String> info = new LinkedHashMap<String, String>(); for (String propertyName : mojo.getProjectProperties()) { String prop = props.get(propertyName); if (prop != null) { info.put(propertyName, prop); } } info.put("build.time", DateFormatUtils.format(new Date(), "d MMMM yyyy, HH:mm:ss ZZ", Locale.ENGLISH)); return info; }
From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectPropertiesProvider.java
License:Apache License
public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) { // finite set of project properties we expose final Map<String, String> projectProperties = new LinkedHashMap<String, String>(65); projectProperties.put("project.id", project.getId()); projectProperties.put("project.groupId", project.getGroupId()); projectProperties.put("project.artifactId", project.getArtifactId()); projectProperties.put("project.version", project.getVersion()); projectProperties.put("project.name", project.getName()); projectProperties.put("project.description", project.getDescription()); projectProperties.put("project.modelVersion", project.getModelVersion()); projectProperties.put("project.inceptionYear", project.getInceptionYear()); projectProperties.put("project.packaging", project.getPackaging()); projectProperties.put("project.url", project.getUrl()); MavenProject parent = project.getParent(); if (parent != null) { projectProperties.put("project.parent.id", parent.getId()); projectProperties.put("project.parent.groupId", parent.getGroupId()); projectProperties.put("project.parent.artifactId", parent.getArtifactId()); projectProperties.put("project.parent.version", parent.getVersion()); projectProperties.put("project.parent.name", parent.getName()); projectProperties.put("project.parent.description", parent.getDescription()); projectProperties.put("project.parent.modelVersion", parent.getModelVersion()); projectProperties.put("project.parent.inceptionYear", parent.getInceptionYear()); projectProperties.put("project.parent.packaging", parent.getPackaging()); projectProperties.put("project.parent.url", parent.getUrl()); }/*from w ww. j a va 2s . co m*/ Map<String, String> info = new LinkedHashMap<String, String>(); new InfoWriter().write(info, mojo.getProjectProperties(), new PropertyMapper() { @Override public String mapProperty(String propertyName) { return projectProperties.get(propertyName); } }); return info; }
From source file:com.simpligility.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 www. j a v a 2 s . c o m final String unpackedLibsFolder = getMojoConfigurationParameter(project, UNPACKED_LIBS_FOLDER_PARAM, null); final UnpackedLibHelper helper = new UnpackedLibHelper(artifactResolverHelper, project, log, unpackedLibsFolder == null ? null : new File(unpackedLibsFolder)); 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); } boolean includeFromAar = getMojoConfigurationParameter(project, INCLUDE_FROM_AAR_PARAM, INCLUDE_FROM_AAR_DEFAULT); boolean includeFromApklib = getMojoConfigurationParameter(project, INCLUDE_FROM_APKLIB_PARAM, INCLUDE_FROM_APKLIB_DEFAULT); boolean disableConflictingDependenciesWarning = getMojoConfigurationParameter(project, DISABLE_CONFLICTING_DEPENDENCIES_WARNING_PARAM, DISABLE_CONFLICTING_DEPENDENCIES_WARNING_DEFAULT); log.debug("projects deps: : " + artifacts); if (!disableConflictingDependenciesWarning) { ProvidedDependencyChecker checker = new ProvidedDependencyChecker(); checker.checkProvidedDependencies(artifacts, log); } 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); // An AAR may also contain zero or more internal libs in the libs folder. // If 'includeLibsJarsFromAar' config param is true then include them too. if (includeFromAar) { // 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)) { if (includeFromApklib) { // Add jar files in 'libs' into classpath. addLibsJarsToClassPath(helper, project, artifact); } } } } if (addedJarFromLibs) { log.warn("Transitive dependencies should really be provided by Maven dependency management.\n" + " We suggest you to ask the above providers to package their component properly.\n" + " Things may break at compile and/or runtime due to multiple copies of incompatible libraries."); } log.debug(""); log.debug("ClasspathModifierLifecycleParticipant#afterProjectsRead - finish"); }
From source file:com.simpligility.maven.plugins.androidndk.common.UnpackedLibHelper.java
License:Open Source License
/** * @return True if this project constructs an APK as opposed to an AAR or APKLIB. */// w ww. j a va 2 s .co m public boolean isAPKBuild(MavenProject project) { return AndroidExtension.APK.equals(project.getPackaging()); }
From source file:com.sixdimensions.wcm.cq.pack.PackageMojo.java
License:Open Source License
public void execute() throws MojoExecutionException { this.getLog().info("execute"); final PackageManagerConfig config = new PackageManagerConfig(); this.initConfig(config); this.getLog().info("Connecting to server: " + config.getHost() + ":" + config.getPort()); this.getLog().info("Connecting with user: " + config.getUser()); this.getLog().debug("Retrieving service"); final PackageManagerService packageMgrSvc = PackageManagerService.Factory.getPackageMgr(config); String packagePath = this.path; if (config.isUseLegacy()) { this.getLog().debug("Checking path: " + packagePath + " for compatibility with legacy API"); final MavenProject project = (MavenProject) this.getPluginContext().get("project"); if (this.path .equals(project.getArtifactId() + "-" + project.getVersion() + "." + project.getPackaging())) { this.getLog().debug("Updating path for legacy API"); packagePath = project.getArtifactId(); } else {/*from w w w. j a va 2 s . com*/ this.getLog().debug("Custom path specified, not modifying"); } } try { if (this.deleteFirst) { try { packageMgrSvc.delete(packagePath); } catch (final Exception e) { this.getLog().warn("Exception deleting existing package, continuing with installation.", e); } } packageMgrSvc.upload(packagePath, this.packageFile); this.getLog().info("Package upload successful"); if (!this.uploadOnly) { packageMgrSvc.install(packagePath); this.getLog().info("Package installation successful"); } } catch (final Exception e) { this.getLog().error("Exception uploading/installing package.", e); throw new MojoExecutionException("Exception uploading/installing package.", e); } this.getLog().info("Package Upload/Installation Completed Successfully"); }
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
/** * When creating {@link MavenProjectRepository} from the current project (which is used * to launch mvn), and if the compile phase has run yet, then the main artifact is * still null.// w ww .j a va 2 s .c o m * * <p> * However, it's often convenient to pick up the files that were left in the file system * from the previous execution. This method checks this situation and updates {@link MavenProject} * accordingly, so that it can be then passed to the constructor of {@link MavenProjectRepository}. * * <p> * Think of this as a pre-processing phase to compensate for the lack of the compile phase * invocation. */ public static void prepareProject(MavenProject project) throws IOException { Artifact ma = project.getArtifact(); if (!project.getPackaging().equals("pom") && ma.getFile() == null) { File outdir = new File(project.getBuild().getOutputDirectory()); if (!outdir.exists()) logger.warning("No output directory " + outdir); else ma.setFile(outdir); } if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. if (ma.getFile().isDirectory()) { // if the main artifact is from target/classes, create META-INF.MF new Packager().writeManifest(project, ma.getFile()); } } }
From source file:com.thalesgroup.dtkit.maven.AbstractSourceJarMojo.java
License:Apache License
protected void packageSources(MavenProject p) throws MojoExecutionException { if (!"pom".equals(p.getPackaging())) { packageSources(Arrays.asList(new Object[] { p })); }/*from ww w . ja v a2s . c o m*/ }
From source file:com.thalesgroup.dtkit.maven.AbstractSourceJarMojo.java
License:Apache License
protected void packageSources(List projects) throws MojoExecutionException { if (project.getArtifact().getClassifier() != null) { getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier " + "per artifact. Current artifact [" + project.getArtifact().getId() + "] has a [" + project.getArtifact().getClassifier() + "] classifier."); return;//from ww w . j av a 2 s . com } MavenArchiver archiver = createArchiver(); for (Iterator i = projects.iterator(); i.hasNext();) { MavenProject subProject = getProject((MavenProject) i.next()); if ("pom".equals(subProject.getPackaging())) { continue; } archiveProjectContent(subProject, archiver.getArchiver()); } if (!archiver.getArchiver().getFiles().isEmpty()) { if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) { getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath()); archive.setManifestFile(defaultManifestFile); } File outputFile = new File(outputDirectory, finalName + "-" + getClassifier() + getExtension()); try { archiver.setOutputFile(outputFile); archive.setAddMavenDescriptor(false); archive.setForced(forceCreation); archiver.createArchive(project, archive); } catch (IOException e) { throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e); } catch (ArchiverException e) { throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e); } catch (ManifestException e) { throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e); } if (attach) { projectHelper.attachArtifact(project, getType(), getClassifier(), outputFile); } else { getLog().info("NOT adding java-sources to attached artifacts list."); } } else { getLog().info("No sources in project. Archive not created."); } }