List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.kie.integration.eap.maven.util.EAPArtifactUtils.java
License:Apache License
public static Artifact createProjectArtifact(MavenProject project) { return EAPArtifactUtils.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging());//from www. java2s .co m }
From source file:org.kie.server.gateway.KieServerGateway.java
License:Apache License
public void deploy(MavenProject project, String container, RuntimeStrategy strategy) throws MojoFailureException { KieContainerResource kieContainer = new KieContainerResource(); kieContainer.setContainerId(container); ReleaseId releaseId = new ReleaseId(); releaseId.setGroupId(project.getGroupId()); releaseId.setArtifactId(project.getArtifactId()); releaseId.setVersion(project.getVersion()); kieContainer.setReleaseId(releaseId); if (strategy != null) { KieServerConfigItem configItem = new KieServerConfigItem(); configItem.setName("RuntimeStrategy"); configItem.setValue(strategy.name()); configItem.setType("BPM"); kieContainer.addConfigItem(configItem); }//from w ww. ja va 2s. c o m ServiceResponse<KieContainerResource> serviceResponse = client.createContainer(container, kieContainer); ServiceResponse.ResponseType type = serviceResponse.getType(); String msg = serviceResponse.getMsg(); LOG.info("Deploy Response: {}", serviceResponse); if (ServiceResponse.ResponseType.FAILURE.equals(type)) { throw new MojoFailureException(msg); } }
From source file:org.kie.server.gateway.KieServerGateway.java
License:Apache License
public void update(MavenProject project, String container) throws MojoFailureException { ReleaseId releaseId = new ReleaseId(); releaseId.setGroupId(project.getGroupId()); releaseId.setArtifactId(project.getArtifactId()); releaseId.setVersion(project.getVersion()); ServiceResponse<ReleaseId> serviceResponse = client.updateReleaseId(container, releaseId); ServiceResponse.ResponseType type = serviceResponse.getType(); String msg = serviceResponse.getMsg(); LOG.info("Replace Response: {}", serviceResponse); if (ServiceResponse.ResponseType.FAILURE.equals(type)) { throw new MojoFailureException(msg); }/*from w ww. ja v a 2s . com*/ }
From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java
License:Apache License
public static String rewriteParent(MavenProject project, Element rootElement, Namespace namespace, Map<String, String> mappedVersions, Map<String, String> originalVersions) throws MojoExecutionException { String parentVersion = null;/* w ww. jav a 2s . c o m*/ if (project.hasParent()) { Element parentElement = rootElement.getChild("parent", namespace); Element versionElement = parentElement.getChild("version", namespace); MavenProject parent = project.getParent(); String key = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId()); parentVersion = mappedVersions.get(key); // if (parentVersion == null) { // //MRELEASE-317 // parentVersion = getResolvedSnapshotVersion(key, resolvedSnapshotDependencies); // } if (parentVersion == null) { if (parent.getVersion().equals(originalVersions.get(key))) { throw new MojoExecutionException( "Version for parent '" + parent.getName() + "' was not mapped"); } } else { rewriteValue(versionElement, parentVersion); } } return parentVersion; }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
License:Educational Community License
public GAV getGav(MavenProject project) { GAV gav = new GAV(); gav.setGroupId(project.getGroupId()); gav.setArtifactId(project.getArtifactId()); gav.setVersion(project.getVersion()); return gav;/*from w w w . jav a2 s . co m*/ }
From source file:org.l2x6.maven.srcdeps.SrcdepsLifecycleParticipant.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { boolean globalSkip = Boolean .valueOf(session.getUserProperties().getProperty(Element.skip.toSrcDepsProperty(), "false")); if (globalSkip) { logger.info("srcdeps-maven-plugin skipped"); return;//from ww w . j a va2s .com } List<String> goals = session.getGoals(); if (goals != null && shouldTriggerSrcdepsBuild(goals)) { List<MavenProject> projects = session.getProjects(); logger.debug("SrcdepsLifecycleParticipant projects = " + projects); Set<Gav> projectGavs = new HashSet<SrcdepsLifecycleParticipant.Gav>(); for (MavenProject project : projects) { projectGavs.add(Gav.ofModel(project.getModel())); } boolean builtSomething = false; for (MavenProject project : projects) { logger.info("srcdeps-maven-plugin scanning project " + project.getGroupId() + ":" + project.getArtifactId()); Optional<Plugin> plugin = findPlugin(project, SrcdepsPluginConstants.ORG_L2X6_MAVEN_SRCDEPS_GROUP_ID, SrcdepsPluginConstants.SRCDEPS_MAVEN_PLUGIN_ADRTIFACT_ID); if (plugin.isPresent() && project.getDependencies() != null) { Optional<Xpp3Dom> conf = plugin.map(Mapper.TO_DOM); if (conf.isPresent()) { MojoExecution mojoExecution = new MojoExecution(plugin.value(), "install", "whatever"); PropsEvaluator evaluator = new PropsEvaluator( new PluginParameterExpressionEvaluator(session, mojoExecution)); SrcdepsConfiguration srcdepsConfiguration = new SrcdepsConfiguration.Builder(evaluator, conf.value(), session, logger).build(); if (srcdepsConfiguration.isSkip()) { logger.info("srcdeps-maven-plugin skipped for project " + project.getGroupId() + ":" + project.getArtifactId()); } else { @SuppressWarnings("unchecked") Map<Dependency, SrcVersion> revisions = filterSrcdeps(project.getDependencies(), projectGavs); if (!revisions.isEmpty()) { assertFailWithProfiles(session, srcdepsConfiguration); new SrcdepsInstaller(session, logger, artifactHandlerManager, srcdepsConfiguration, revisions, buildService).install(); builtSomething = true; } } } } } if (builtSomething) { Optional<Plugin> plugin = findPlugin(session.getTopLevelProject(), "org.apache.maven.plugins", "maven-clean-plugin"); if (plugin.isPresent()) { addCleanExclude(session.getTopLevelProject(), plugin.value()); } } } }
From source file:org.mobicents.maven.plugin.eclipse.ClasspathWriter.java
License:Open Source License
/** * Writes the .classpath file for eclipse. * /* ww w . j a va 2 s .c o m*/ * @param projects * the list of projects from which the .classpath will get its * dependencies. * @param repositoryVariableName * the name of the maven repository variable. * @param artifactFactory * the factory for constructing artifacts. * @param artifactResolver * the artifact resolver. * @param localRepository * the local repository instance. * @param artifactMetadataSource * @param classpathArtifactTypes * the artifacts types that are allowed in the classpath file. * @param remoteRepositories * the list of remote repository instances. * @param resolveTransitiveDependencies * whether or not dependencies shall be transitively resolved. * @param merge * anything extra (not auto-generated), that should be "merged" * into the generated .classpath * @param classpathExcludes * @param includeTestsDirectory * @param includeResourcesDirectory * @throws Exception */ public void write(final List projects, final String repositoryVariableName, final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver, final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource, final Set classpathArtifactTypes, final List remoteRepositories, final boolean resolveTransitiveDependencies, final String merge, Set classpathExcludes, boolean includeResourcesDirectory) throws Exception { final String rootDirectory = PathNormalizer.normalizePath(this.project.getBasedir().toString()); final File classpathFile = new File(rootDirectory, ".classpath"); final FileWriter fileWriter = new FileWriter(classpathFile); final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter, "UTF-8", null); writer.startElement("classpath"); final Set projectArtifactIds = new LinkedHashSet(); for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); final Artifact projectArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging()); projectArtifactIds.add(projectArtifact.getId()); } // - collect the source roots for the root project (if they are any) Set<String> sourceRoots = collectSourceRoots(this.project, rootDirectory, writer, includeResourcesDirectory); final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(artifactFactory, null, null)); for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); sourceRoots.addAll(collectSourceRoots(project, rootDirectory, writer, includeResourcesDirectory)); final Set artifacts = project.createArtifacts(artifactFactory, null, null); // - get the direct dependencies for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();) { final Artifact artifact = (Artifact) artifactIterator.next(); // - don't attempt to resolve the artifact if its part of the // project (we // infer this if it has the same id has one of the projects or // is in // the same groupId). if (!projectArtifactIds.contains(artifact.getId()) && !project.getGroupId().equals(artifact.getGroupId())) { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); allArtifacts.add(artifact); } else { allArtifacts.add(artifact); } } } // we have all source roots now, sort and write for (String sourceRoot : sourceRoots) { logger.info("Adding src path " + sourceRoot); this.writeClasspathEntry(writer, "src", sourceRoot); } // - remove the project artifacts for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); final Artifact projectArtifact = project.getArtifact(); if (projectArtifact != null) { for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();) { final Artifact artifact = (Artifact) artifactIterator.next(); final String projectId = projectArtifact.getArtifactId(); final String projectGroupId = projectArtifact.getGroupId(); final String artifactId = artifact.getArtifactId(); final String groupId = artifact.getGroupId(); if (artifactId.equals(projectId) && groupId.equals(projectGroupId)) { artifactIterator.remove(); } } } } // - now we resolve transitively, if we have the flag on if (resolveTransitiveDependencies) { final Artifact rootProjectArtifact = artifactFactory.createArtifact(this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(), null, this.project.getPackaging()); final OrArtifactFilter filter = new OrArtifactFilter(); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED)); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST)); final ArtifactResolutionResult result = artifactResolver.resolveTransitively(allArtifacts, rootProjectArtifact, localRepository, remoteRepositories, artifactMetadataSource, filter); allArtifacts.clear(); allArtifacts.addAll(result.getArtifacts()); } // remove excluded ones for (Iterator i = allArtifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if (classpathExcludes != null) { if (classpathExcludes.contains(artifact.getGroupId())) { logger.info("Excluding " + artifact + " from .classpath, groupId is excluded"); i.remove(); } else if (classpathExcludes.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) { logger.info("Excluding " + artifact + " from .classpath, groupId:artifactId is excluded"); i.remove(); } else if (classpathExcludes.contains( artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion())) { logger.info( "Excluding " + artifact + " from .classpath, groupId:artifactId:version is excluded"); i.remove(); } } } final List allArtifactPaths = new ArrayList(allArtifacts); for (final ListIterator iterator = allArtifactPaths.listIterator(); iterator.hasNext();) { final Artifact artifact = (Artifact) iterator.next(); if (classpathArtifactTypes.contains(artifact.getType())) { File artifactFile = artifact.getFile(); if (artifactFile == null) { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); artifactFile = artifact.getFile(); } if (artifactFile != null) { final String path = StringUtils.replace(PathNormalizer.normalizePath(artifactFile.toString()), PathNormalizer.normalizePath(localRepository.getBasedir()), repositoryVariableName); iterator.set(path); } else { iterator.remove(); } } else { iterator.remove(); } } // - sort the paths Collections.sort(allArtifactPaths); for (final Iterator iterator = allArtifactPaths.iterator(); iterator.hasNext();) { String path = (String) iterator.next(); if (path.startsWith(repositoryVariableName)) { this.writeClasspathEntry(writer, "var", path); } else { if (path.startsWith(rootDirectory)) { path = StringUtils.replace(path, rootDirectory + '/', ""); } this.writeClasspathEntry(writer, "lib", path); } } this.writeClasspathEntry(writer, "con", "org.eclipse.jdt.launching.JRE_CONTAINER"); String outputPath = StringUtils.replace( PathNormalizer.normalizePath(this.project.getBuild().getOutputDirectory()), rootDirectory, ""); if (outputPath.startsWith("/")) { outputPath = outputPath.substring(1, outputPath.length()); } this.writeClasspathEntry(writer, "output", outputPath); if (StringUtils.isNotBlank(merge)) { writer.writeMarkup(merge); } writer.endElement(); logger.info("Classpath file written --> '" + classpathFile + "'"); IOUtil.close(fileWriter); }
From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java
License:Apache License
private String getOutputDirectory(String output, MavenProject project, boolean includeBaseDirectory) { String value = output;// w ww . ja v a 2 s. c o m if (value == null) { value = ""; } if (!value.endsWith("/") && !value.endsWith("\\")) { // TODO: shouldn't archiver do this? value += '/'; } if (includeBaseDirectory) { if (value.startsWith("/")) { value = finalName + value; } else { value = finalName + "/" + value; } } else { if (value.startsWith("/")) { value = value.substring(1); } } if (project != null) { value = StringUtils.replace(value, "${groupId}", project.getGroupId()); value = StringUtils.replace(value, "${artifactId}", project.getArtifactId()); value = StringUtils.replace(value, "${version}", project.getVersion()); Build build = project.getBuild(); value = StringUtils.replace(value, "${build.finalName}", build.getFinalName()); value = StringUtils.replace(value, "${finalName}", build.getFinalName()); } return value; }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze major project and build the right pax-create-project call * // w ww. j av a 2 s. c o m * @param script build script * @param project major Maven project */ private void handleMajorProject(PaxScript script, MavenProject project) { if (unify && !project.isExecutionRoot()) { // exclude the local poms settings from the unified project m_handledDirs.add(new File(project.getBasedir(), "poms")); return; } PaxCommandBuilder command = script.call(PaxScript.CREATE_PROJECT); command.option('g', project.getGroupId()); command.option('a', project.getArtifactId()); command.option('v', project.getVersion()); setTargetDirectory(command, project.getBasedir().getParentFile()); registerProject(project); m_majorProjectMap.put(project, command); }
From source file:org.ops4j.pax.construct.clone.CloneMojo.java
License:Apache License
/** * Analyze bundle project and determine if any pax-create-bundle or pax-wrap-jar calls are needed * //w w w . ja v a 2 s .c om * @param script build script * @param project Maven bundle project * @throws MojoExecutionException */ private void handleBundleProject(PaxScript script, MavenProject project) throws MojoExecutionException { PaxCommandBuilder command; String bundleName; String namespace = findBundleNamespace(project); if (null != namespace) { bundleName = project.getArtifactId(); command = script.call(PaxScript.CREATE_BUNDLE); command.option('p', namespace); if (!bundleName.equals(namespace)) { command.option('n', bundleName); } command.option('v', project.getVersion()); command.maven().flag("noDeps"); } else { Dependency wrappee = findWrappee(project); if (wrappee != null) { command = script.call(PaxScript.WRAP_JAR); command.option('g', wrappee.getGroupId()); command.option('a', wrappee.getArtifactId()); command.option('v', wrappee.getVersion()); if (repair) { // this is expected to be the generated bundle name bundleName = PomUtils.getCompoundId(wrappee.getGroupId(), wrappee.getArtifactId()); // detect if we need to add the version back later on... if (project.getArtifactId().endsWith(wrappee.getVersion())) { command.maven().flag("addVersion"); } } else { bundleName = project.getArtifactId(); // need to retain the old name and version settings command.maven().option("bundleName", bundleName); command.maven().option("bundleVersion", project.getVersion()); } } else { getLog().warn("Unable to clone bundle project " + project.getId()); return; } } Pom customizedPom = null; if (repair) { // fix references to local bundles by re-importing customizedPom = repairBundleImports(script, project); } else { // need to keep old groupId intact (name is already retained) command.maven().option("bundleGroupId", project.getGroupId()); } addFragmentToCommand(command, createBundleArchetype(project, namespace, customizedPom)); setTargetDirectory(command, project.getBasedir().getParentFile()); registerProject(project); registerBundleName(project, bundleName); }