List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:com.googlecode.bdoc.mojo.RootPackageGenerator.java
License:Open Source License
public static String calculateRootPackage(MavenProject project) { String groupId = project.getGroupId(); String artifactId = project.getArtifactId(); String result = null;/*from w w w .j a v a 2 s . c o m*/ if (groupId.equals(artifactId) || groupId.endsWith(artifactId)) { result = groupId; } else { String[] groupIdPices = groupId.split("\\."); if (1 == groupIdPices.length) { groupIdPices = groupId.split("-"); } if (0 < groupIdPices.length) { String groupIdPostfix = groupIdPices[groupIdPices.length - 1]; String[] artifactIdPices = artifactId.split("-"); String artifactIdPrefix = artifactIdPices[0]; if (groupIdPostfix.equals(artifactIdPrefix)) { result = groupId + artifactId.substring(artifactIdPrefix.length()); } } } if (null == result) { result = groupId; } return result.replace('-', '.'); }
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());/*from www . j a v a 2 s. c o m*/ mavenGAV.setPackaging(mavenProject.getPackaging()); return projectFile; }
From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java
License:Apache License
private Collection<String> createManifest() { MavenProject project = getProject(); return Arrays.asList("#appname: " + getEscapedName(), "#publisher: " + getPublisher(project), "#url: " + getUrl(project), "#image: " + getIcon(), "#appid: " + project.getGroupId() + '.' + project.getArtifactId(), "#desc: " + project.getDescription(), "#type: desktop", "#guid: " + UUID.randomUUID(), "runtime:" + getSdkVersion(), "app:" + getSdkVersion(), "codec:" + getSdkVersion(), "database:" + getSdkVersion(), "filesystem:" + getSdkVersion(), "media:" + getSdkVersion(), "monkey:" + getSdkVersion(), "network:" + getSdkVersion(), "platform:" + getSdkVersion(), "process:" + getSdkVersion(), "ui:" + getSdkVersion(), "worker:" + getSdkVersion()); }
From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java
License:Apache License
private Collection<String> createXml() { return new ArrayList<String>() { {/*from w ww .j a va 2 s . c o m*/ add("<?xml version='1.0' encoding='UTF-8'?>"); add("<ti:app xmlns:ti='http://ti.appcelerator.org'>"); MavenProject project = getProject(); add("<id>" + project.getGroupId() + '.' + project.getArtifactId() + "</id>"); add("<name>" + getName() + "</name>"); add("<version>" + project.getVersion() + "</version>"); String publisher = getPublisher(project); if (publisher != null) { add("<publisher>" + publisher + "</publisher>"); add("<copyright>" + Calendar.getInstance().get(Calendar.YEAR) + " " + publisher + "</copyright>"); } String url = getUrl(project); if (url != null) add("<url>" + url + "</url>"); String icon = getIcon(); if (icon != null) add("<icon>" + icon + "</icon>"); addAll(getDisplay().createXml(getName(), getIndex())); add("</ti:app>"); } }; }
From source file:com.helger.maven.buildinfo.GenerateBuildInfoMojo.java
License:Apache License
private Map<String, String> _determineBuildInfoProperties() { // Get the current time, using the time zone specified in the settings final DateTime aDT = PDTFactory.getCurrentDateTime(); // Build the default properties final Map<String, String> aProps = new LinkedHashMap<String, String>(); // Version 1: initial // Version 2: added dependency information; added per build plugin the key // property/* w w w . j a v a 2 s . c o m*/ aProps.put("buildinfo.version", "2"); // Project information aProps.put("project.groupid", project.getGroupId()); aProps.put("project.artifactid", project.getArtifactId()); aProps.put("project.version", project.getVersion()); aProps.put("project.name", project.getName()); aProps.put("project.packaging", project.getPackaging()); // Parent project information (if available) final MavenProject aParentProject = project.getParent(); if (aParentProject != null) { aProps.put("parentproject.groupid", aParentProject.getGroupId()); aProps.put("parentproject.artifactid", aParentProject.getArtifactId()); aProps.put("parentproject.version", aParentProject.getVersion()); aProps.put("parentproject.name", aParentProject.getName()); } // All reactor projects (nested projects) // Don't emit this, if this is "1" as than only the current project would be // listed if (reactorProjects != null && reactorProjects.size() != 1) { final String sPrefix = "reactorproject."; // The number of reactor projects aProps.put(sPrefix + "count", Integer.toString(reactorProjects.size())); // Show details of all reactor projects, index starting at 0 int nIndex = 0; for (final MavenProject aReactorProject : reactorProjects) { aProps.put(sPrefix + nIndex + ".groupid", aReactorProject.getGroupId()); aProps.put(sPrefix + nIndex + ".artifactid", aReactorProject.getArtifactId()); aProps.put(sPrefix + nIndex + ".version", aReactorProject.getVersion()); aProps.put(sPrefix + nIndex + ".name", aReactorProject.getName()); ++nIndex; } } // Build Plugins final List<?> aBuildPlugins = project.getBuildPlugins(); if (aBuildPlugins != null) { final String sPrefix = "build.plugin."; // The number of build plugins aProps.put(sPrefix + "count", Integer.toString(aBuildPlugins.size())); // Show details of all plugins, index starting at 0 int nIndex = 0; for (final Object aObj : aBuildPlugins) { final Plugin aPlugin = (Plugin) aObj; aProps.put(sPrefix + nIndex + ".groupid", aPlugin.getGroupId()); aProps.put(sPrefix + nIndex + ".artifactid", aPlugin.getArtifactId()); aProps.put(sPrefix + nIndex + ".version", aPlugin.getVersion()); final Object aConfiguration = aPlugin.getConfiguration(); if (aConfiguration != null) { // Will emit an XML structure! aProps.put(sPrefix + nIndex + ".configuration", aConfiguration.toString()); } aProps.put(sPrefix + nIndex + ".key", aPlugin.getKey()); ++nIndex; } } // Build dependencies final List<?> aDependencies = project.getDependencies(); if (aDependencies != null) { final String sDepPrefix = "dependency."; // The number of build plugins aProps.put(sDepPrefix + "count", Integer.toString(aDependencies.size())); // Show details of all dependencies, index starting at 0 int nDepIndex = 0; for (final Object aDepObj : aDependencies) { final Dependency aDependency = (Dependency) aDepObj; aProps.put(sDepPrefix + nDepIndex + ".groupid", aDependency.getGroupId()); aProps.put(sDepPrefix + nDepIndex + ".artifactid", aDependency.getArtifactId()); aProps.put(sDepPrefix + nDepIndex + ".version", aDependency.getVersion()); aProps.put(sDepPrefix + nDepIndex + ".type", aDependency.getType()); if (aDependency.getClassifier() != null) aProps.put(sDepPrefix + nDepIndex + ".classifier", aDependency.getClassifier()); aProps.put(sDepPrefix + nDepIndex + ".scope", aDependency.getScope()); if (aDependency.getSystemPath() != null) aProps.put(sDepPrefix + nDepIndex + ".systempath", aDependency.getSystemPath()); aProps.put(sDepPrefix + nDepIndex + ".optional", Boolean.toString(aDependency.isOptional())); aProps.put(sDepPrefix + nDepIndex + ".managementkey", aDependency.getManagementKey()); // Add all exclusions of the current dependency final List<?> aExclusions = aDependency.getExclusions(); if (aExclusions != null) { final String sExclusionPrefix = sDepPrefix + nDepIndex + ".exclusion."; // The number of build plugins aProps.put(sExclusionPrefix + "count", Integer.toString(aExclusions.size())); // Show details of all dependencies, index starting at 0 int nExclusionIndex = 0; for (final Object aExclusionObj : aExclusions) { final Exclusion aExclusion = (Exclusion) aExclusionObj; aProps.put(sExclusionPrefix + nExclusionIndex + ".groupid", aExclusion.getGroupId()); aProps.put(sExclusionPrefix + nExclusionIndex + ".artifactid", aExclusion.getArtifactId()); ++nExclusionIndex; } } ++nDepIndex; } } // Build date and time aProps.put("build.datetime", aDT.toString()); aProps.put("build.datetime.millis", Long.toString(aDT.getMillis())); aProps.put("build.datetime.date", aDT.toLocalDate().toString()); aProps.put("build.datetime.time", aDT.toLocalTime().toString()); aProps.put("build.datetime.timezone", aDT.getZone().getID()); final int nOfsMilliSecs = aDT.getZone().getOffset(aDT); aProps.put("build.datetime.timezone.offsethours", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_HOUR)); aProps.put("build.datetime.timezone.offsetmins", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_MINUTE)); aProps.put("build.datetime.timezone.offsetsecs", Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_SECOND)); aProps.put("build.datetime.timezone.offsetmillisecs", Integer.toString(nOfsMilliSecs)); // Emit system properties? if (withAllSystemProperties || CollectionHelper.isNotEmpty(selectedSystemProperties)) for (final Map.Entry<String, String> aEntry : CollectionHelper .getSortedByKey(SystemProperties.getAllProperties()).entrySet()) { final String sName = aEntry.getKey(); if (withAllSystemProperties || _matches(selectedSystemProperties, sName)) if (!_matches(ignoredSystemProperties, sName)) aProps.put("systemproperty." + sName, aEntry.getValue()); } // Emit environment variable? if (withAllEnvVars || CollectionHelper.isNotEmpty(selectedEnvVars)) for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(System.getenv()) .entrySet()) { final String sName = aEntry.getKey(); if (withAllEnvVars || _matches(selectedEnvVars, sName)) if (!_matches(ignoredEnvVars, sName)) aProps.put("envvar." + sName, aEntry.getValue()); } return aProps; }
From source file:com.kamomileware.maven.plugin.opencms.packaging.ClassesPackagingTask.java
License:Apache License
protected void generateJarArchive(ModulePackagingContext context) throws MojoExecutionException { MavenProject project = context.getProject(); ArtifactFactory factory = context.getArtifactFactory(); Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar"); String archiveName = null;// w w w. ja va 2 s .c om try { archiveName = getArtifactFinalName(context, artifact); } catch (InterpolationException e) { throw new MojoExecutionException("Could not get the final name of the artifact[" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e); } final String targetFilename = LIB_PATH + archiveName; if (context.getModuleStructure().registerFile("currentBuild", targetFilename)) { File base = context.getModuleSourceTargetDirectory() == null ? context.getModuleDirectory() : new File(context.getModuleDirectory(), context.getModuleSourceTargetDirectory()); final File libDirectory = new File(base, LIB_PATH); final File jarFile = new File(libDirectory, archiveName); final ClassesPackager packager = new ClassesPackager(); packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), project, context.getArchive()); } else { context.getLog().warn( "Could not generate archive classes file[" + targetFilename + "] has already been copied."); } }
From source file:com.monday_consulting.maven.plugins.fsm.DependencyToXMLMojo.java
License:Apache License
/** * Log Projects and their resolved dependencies via MavenProject.getArtifacts(). * * @param reactorProjects MavenProjects in the current reactor *//* www. j a va 2 s . c o m*/ private void checkReactor(final List<MavenProject> reactorProjects) { for (final MavenProject reactorProject : reactorProjects) { final String msg = "Check resolved Artifacts for: " + "\ngroudId: " + reactorProject.getGroupId() + "\nartifactId: " + reactorProject.getArtifactId() + "\nversion: " + reactorProject.getVersion(); if (getLog().isDebugEnabled()) getLog().debug(msg); if (reactorProject.getArtifacts() == null || reactorProject.getArtifacts().isEmpty()) { if (getLog().isDebugEnabled()) getLog().debug("+ Dependencies not resolved or Reactor-Project has no dependencies!"); } else { for (final Artifact artifact : reactorProject.getArtifacts()) { if (getLog().isDebugEnabled()) getLog().debug(" + " + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : " + artifact.getVersion() + " : " + artifact.getType() + " : " + artifact.getFile()); } } } }
From source file:com.monday_consulting.maven.plugins.fsm.util.resolver.MavenGetArtifactsResolver.java
License:Apache License
private MavenProject getMavenProjectViaReactor(final Module module) { MavenProject mProject = null;/* w w w . j a v a2s . c om*/ boolean moduleInReactor = false; for (final MavenProject prj : reactorProjects) { if ((prj.getArtifactId().equals(module.getArtifactId())) && (prj.getGroupId().equals(module.getGroupId()))) { if (moduleInReactor) { log.error("module " + module.getGroupId() + ":" + module.getArtifactId() + " found twice in reactor!"); } else { log.info("module " + module.getGroupId() + ":" + module.getArtifactId() + " found in reactor!"); moduleInReactor = true; mProject = prj; } } } if (!moduleInReactor) { log.warn("module " + module.getGroupId() + ":" + module.getArtifactId() + " not found in reactor!"); } return mProject; }
From source file:com.oracle.istack.maven.PropertyResolver.java
License:Open Source License
/** * * @param project maven project/*from www.ja v a2 s.c o m*/ * @throws FileNotFoundException properties not found * @throws IOException IO error * @throws XmlPullParserException error parsing xml */ public void resolveProperties(MavenProject project) throws FileNotFoundException, IOException, XmlPullParserException { logger.info("Resolving properties for " + project.getGroupId() + ":" + project.getArtifactId()); Model model = null; FileReader reader; try { reader = new FileReader(project.getFile()); model = mavenreader.read(reader); } catch (FileNotFoundException ex) { Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex); } MavenProject loadedProject = new MavenProject(model); DependencyManagement dm = loadedProject.getDependencyManagement(); if (dm == null) { logger.warn("No dependency management section found in: " + loadedProject.getGroupId() + ":" + loadedProject.getArtifactId()); return; } List<Dependency> depList = dm.getDependencies(); DependencyResult result; for (Dependency d : depList) { if ("import".equals(d.getScope())) { try { String version = d.getVersion(); logger.info("Imported via import-scope: " + d.getGroupId() + ":" + d.getArtifactId() + ":" + version); if (version.contains("$")) { version = properties .getProperty(version.substring(version.indexOf('{') + 1, version.lastIndexOf('}'))); logger.info("Imported version resolved to: " + version); } d.setVersion(version); d.setType("pom"); d.setClassifier("pom"); result = DependencyResolver.resolve(d, pluginRepos, repoSystem, repoSession); Artifact a = result.getArtifactResults().get(0).getArtifact(); reader = new FileReader(a.getFile()); Model m = mavenreader.read(reader); MavenProject p = new MavenProject(m); p.setFile(a.getFile()); for (Map.Entry<Object, Object> e : p.getProperties().entrySet()) { logger.info("Setting property: " + (String) e.getKey() + ":" + (String) e.getValue()); properties.setProperty((String) e.getKey(), (String) e.getValue()); } resolveProperties(p); } catch (DependencyResolutionException ex) { Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.Package.java
License:Open Source License
@Override protected void invoke(Diagnostic result) throws Exception { Collection<File> moduleRoots = findModuleRoots(); if (moduleRoots.isEmpty()) { result.addChild(new Diagnostic(ERROR, PACKAGE, "No modules found in repository")); return;//w w w . j a va 2s. co m } File buildDir = getBuildDir(); buildDir.mkdirs(); if (moduleRoots.size() == 1) { MavenProject project = getProject(); File moduleRoot = moduleRoots.iterator().next(); Metadata[] resultingMetadata = new Metadata[1]; byte[][] resultingMD5 = new byte[1][]; project.getArtifact() .setFile(buildForge(moduleRoot, buildDir, resultingMetadata, resultingMD5, result)); Artifact pmriArtifact = repositorySystem.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "compile", "pmri"); PuppetModuleReleaseInfo pmri = new PuppetModuleReleaseInfo(); pmri.setMetadata(resultingMetadata[0]); pmri.populate(moduleRoot); File pmriFile = new File(buildDir, "release.pmri"); OutputStream out = new FileOutputStream(pmriFile); try { Writer writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); getGson().toJson(pmri, writer); writer.flush(); } finally { out.close(); } pmriArtifact.setFile(pmriFile); pmriArtifact.setResolved(true); project.addAttachedArtifact(pmriArtifact); } else { File builtModules = new File(buildDir, "builtModules"); if (!(builtModules.mkdir() || builtModules.isDirectory())) { result.addChild( new Diagnostic(ERROR, PACKAGE, "Unable to create directory" + builtModules.getPath())); return; } for (File moduleRoot : moduleRoots) buildForge(moduleRoot, builtModules, null, null, result); } }