List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:com.torchmind.maven.plugins.attribution.AttributionMojo.java
License:Apache License
/** * Creates an artifact using a maven project. * @param artifact the maven project.//from w w w . j a v a2 s . c o m * @return the artifact. */ @Nonnull public static Artifact createArtifact(@Nonnull MavenProject artifact) { return new Artifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getName(), artifact.getDescription(), artifact.getUrl(), artifact.getLicenses().stream().map(AttributionMojo::createLicense).collect(Collectors.toList()), artifact.getDevelopers().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList()), artifact.getContributors().stream().map(AttributionMojo::createDeveloper) .collect(Collectors.toList())); }
From source file:com.tvarit.plugin.TvaritTomcatDeployerMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { final MavenProject project = (MavenProject) this.getPluginContext().getOrDefault("project", null); if (templateUrl == null) try {// ww w .ja v a 2s . com templateUrl = new TemplateUrlMaker().makeUrl(project, "newinstance.template").toString(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Could not create default url for templates. Please open an issue on github.", e); } final BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client s3Client = new AmazonS3Client(awsCredentials); final File warFile = project.getArtifact().getFile(); final String key = "deployables/" + project.getGroupId() + "/" + project.getArtifactId() + "/" + project.getVersion() + "/" + warFile.getName(); final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, warFile); final ObjectMetadata metadata = new ObjectMetadata(); final HashMap<String, String> userMetadata = new HashMap<>(); userMetadata.put("project_name", projectName); userMetadata.put("stack_template_url", templateUrl); userMetadata.put("private_key_name", sshKeyName); metadata.setUserMetadata(userMetadata); putObjectRequest.withMetadata(metadata); final PutObjectResult putObjectResult = s3Client.putObject(putObjectRequest); /* AmazonCloudFormationClient amazonCloudFormationClient = new AmazonCloudFormationClient(awsCredentials); final com.amazonaws.services.cloudformation.model.Parameter projectNameParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("projectName").withParameterValue(this.projectName); final com.amazonaws.services.cloudformation.model.Parameter publicSubnetsParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("publicSubnets").withParameterValue(commaSeparatedSubnetIds); final com.amazonaws.services.cloudformation.model.Parameter tvaritRoleParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("tvaritRole").withParameterValue(tvaritRole); final com.amazonaws.services.cloudformation.model.Parameter tvaritInstanceProfileParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("tvaritInstanceProfile").withParameterValue(this.tvaritInstanceProfile); final com.amazonaws.services.cloudformation.model.Parameter tvaritBucketNameParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("bucketName").withParameterValue(this.bucketName); final com.amazonaws.services.cloudformation.model.Parameter instanceSecurityGroupIdParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("sgId").withParameterValue(this.instanceSecurityGroupId); final com.amazonaws.services.cloudformation.model.Parameter sshKeyNameParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("keyName").withParameterValue(this.sshKeyName); final String warFileUrl = s3Client.getUrl(bucketName, key).toString(); final com.amazonaws.services.cloudformation.model.Parameter warFileUrlParameter = new com.amazonaws.services.cloudformation.model.Parameter().withParameterKey("warFileUrl").withParameterValue(warFileUrl); final CreateStackRequest createStackRequest = new CreateStackRequest(); if (templateUrl == null) { try { templateUrl = new TemplateUrlMaker().makeUrl(project, "newinstance.template").toString(); } catch (MalformedURLException e) { throw new MojoExecutionException("Could not create default url for templates. Please open an issue on github.", e); } } createStackRequest. withStackName(projectName + "-instance-" + project.getVersion().replace(".", "-")). withParameters( projectNameParameter, publicSubnetsParameter, tvaritInstanceProfileParameter, tvaritRoleParameter, tvaritBucketNameParameter, instanceSecurityGroupIdParameter, warFileUrlParameter, sshKeyNameParameter ). withDisableRollback(true). withTemplateURL(templateUrl); createStackRequest.withDisableRollback(true); final Stack stack = new StackMaker().makeStack(createStackRequest, amazonCloudFormationClient, getLog()); AmazonAutoScalingClient amazonAutoScalingClient = new AmazonAutoScalingClient(awsCredentials); final AttachInstancesRequest attachInstancesRequest = new AttachInstancesRequest(); attachInstancesRequest.withInstanceIds(stack.getOutputs().get(0).getOutputValue(), stack.getOutputs().get(1).getOutputValue()).withAutoScalingGroupName(autoScalingGroupName); amazonAutoScalingClient.attachInstances(attachInstancesRequest); */ }
From source file:de.akquinet.innovation.continuous.UniqueVersionMojo.java
License:Apache License
public void updateReleaseProperties(String newVersion) throws IOException { Properties properties = new Properties(); File releaseFile = new File(project.getBasedir(), "release.properties"); if (releaseFile.exists()) { FileInputStream fis = new FileInputStream(releaseFile); properties.load(fis);/*from ww w . ja v a 2 s . com*/ IOUtils.closeQuietly(fis); } properties.put("scm.tag", project.getArtifactId() + "-" + newVersion); String oldVersion = project.getVersion(); // For all projects set: //project.rel.org.myCompany\:projectA=1.2 //project.dev.org.myCompany\:projectA=1.3-SNAPSHOT for (MavenProject project : reactor) { properties.put("project.rel." + project.getGroupId() + ":" + project.getArtifactId(), newVersion); properties.put("project.dev." + project.getGroupId() + ":" + project.getArtifactId(), oldVersion); } FileOutputStream fos = new FileOutputStream(releaseFile); properties.store(fos, "File edited by the continuous-version-maven-plugin"); IOUtils.closeQuietly(fos); }
From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java
private Dependency mapDependency(DependencyNode node, Map<ComponentId, Map.Entry<MavenProject, String[]>> projectLookup) { Dependency.Builder builder = new Dependency.Builder(); Artifact artifact = node.getArtifact(); ComponentId artifactId = ComponentId.create(artifact); Map.Entry<MavenProject, String[]> projectLicensesPair = projectLookup.get(artifactId); // try fallback to artifact baseVersion, (for example because a snapshot is locked ) if (projectLicensesPair == null) { projectLicensesPair = projectLookup.get(ComponentId.createFallback(artifact)); }/* w w w. ja v a 2 s .co m*/ if (projectLicensesPair == null) { getLog().error("Something weird happened: no Project found for artifact: " + artifactId); return null; } MavenProject project = projectLicensesPair.getKey(); String[] licensesArr = projectLicensesPair.getValue(); builder.setName(project.getName()).setDescription(project.getDescription()) .setKey("mvn:" + project.getGroupId() + ':' + project.getArtifactId()) .addVersion(project.getVersion()).setHomepageUrl(project.getUrl()); if (isPrivateComponent(project)) { builder.setPrivate(true); } try { File file = artifact.getFile(); if (file != null) { builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(file)); } else { Artifact af = findProjectArtifact(artifact); if (af != null && af.getFile() != null) { builder.setChecksum("sha-1:" + ChecksumCreator.createChecksum(af.getFile())); } else { getLog().warn( "Could not generate checksum - no file specified: " + ComponentId.create(artifact)); } } } catch (NoSuchAlgorithmException | IOException e) { getLog().warn("Could not generate checksum: " + e.getMessage()); } if (licensesArr != null && (licensesArr.length != 1 || !LicenseMap.UNKNOWN_LICENSE_MESSAGE.equals(licensesArr[0]))) { for (String license : licensesArr) { builder.addLicense(license); } } for (DependencyNode childNode : node.getChildren()) { Dependency dep = mapDependency(childNode, projectLookup); if (dep != null) { builder.addDependency(dep); } } return builder.buildDependency(); }
From source file:de.lightful.maven.plugins.drools.impl.dependencies.DependencyLoader.java
License:Apache License
private Dependency createDependencyFrom(MavenProject project) { final String artifactType = project.getPackaging(); org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), EMPTY_CLASSIFIER, fileExtensionOf(artifactType), project.getVersion()); return new Dependency(artifact, WellKnownNames.SCOPE_COMPILE); }
From source file:de.saumya.mojo.gem.GemspecWriter.java
@SuppressWarnings("unchecked") GemspecWriter(final File gemspec, final MavenProject project, final GemArtifact artifact) throws IOException { this.latestModified = project.getFile() == null ? 0 : project.getFile().lastModified(); this.gemspec = gemspec; this.gemspec.getParentFile().mkdirs(); this.writer = new FileWriter(gemspec); this.project = project; append("Gem::Specification.new do |s|"); append("name", artifact.getGemName()); append("version", gemVersion(project.getVersion())); append();/* w w w. j av a 2 s . com*/ append("summary", project.getName()); append("description", project.getDescription()); append("homepage", project.getUrl()); append(); for (final Developer developer : (List<Developer>) project.getDevelopers()) { appendAuthor(developer.getName(), developer.getEmail()); } for (final Contributor contributor : (List<Contributor>) project.getContributors()) { appendAuthor(contributor.getName(), contributor.getEmail()); } append(); for (final License license : (List<License>) project.getLicenses()) { appendLicense(license.getUrl(), license.getName()); } }
From source file:fr.brouillard.oss.jgitver.GAV.java
License:Apache License
/** * Builds a GAV object from the given MavenProject object. * //from w w w .jav a2s. c o m * @param project the project to extract info from * @return a new GAV object */ public static GAV from(MavenProject project) { return new GAV(project.getGroupId(), project.getArtifactId(), project.getVersion()); }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.AbstractPOMGenerator.java
License:Apache License
protected void generateDeployPOM(MavenProject project) throws MojoExecutionException { File outputFile = getOutputFile(); File templateFile = getTemplateFile(); getLog().info(templateFile.getAbsolutePath()); InputStream builtinTemplateFile = getBuiltinTemplateFile(); getLog().info(getGenerationMessage() + "'" + outputFile.getAbsolutePath() + "'"); try {/*from w w w. j a v a 2s . co m*/ outputFile.getParentFile().mkdirs(); outputFile.createNewFile(); if (templateFile != null && templateFile.exists() && !getTemplateMerge()) { FileUtils.copyFile(templateFile, outputFile); // if a template deploy POM exists and we don't want to merge with built-in one: use it } else { // otherwise : use the one included in the plugin FileOutputStream fos = new FileOutputStream(outputFile); IOUtils.copy(builtinTemplateFile, fos); } } catch (IOException e) { throw new MojoExecutionException(getFailureMessage()); } try { Model model = POMManager.getModelFromPOM(outputFile, this.getLog()); if (templateFile != null && templateFile.exists() && getTemplateMerge()) { model = POMManager.mergeModelFromPOM(templateFile, model, this.getLog()); // if a template deploy POM exists and we want to merge with built-in one: merge it } model.setGroupId(project.getGroupId()); model.setArtifactId(project.getArtifactId()); model.setVersion(project.getVersion()); Properties originalProperties = getProject().getProperties(); for (String property : originalProperties.stringPropertyNames()) { if (property != null && property.startsWith(deploymentPropertyPrefix)) { model.getProperties().put(property.substring(deploymentPropertyPrefix.length()), originalProperties.getProperty(property)); } if (property != null && deploymentProperties.contains(property)) { model.getProperties().put(property, originalProperties.getProperty(property)); } } model = updateModel(model, project); POMManager.writeModelToPOM(model, outputFile, getLog()); attachFile(outputFile); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (XmlPullParserException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.GenerateRootDeploymentPOM.java
License:Apache License
private MavenProject isProjectActive(Model model, List<MavenProject> activeProjects) { for (MavenProject mavenProject : activeProjects) { String packageSkipProperty = mavenProject.getProperties().getProperty("bw.package.skip"); boolean packageSkip = packageSkipProperty != null && packageSkipProperty.equals("true"); if ((mavenProject.getGroupId().equals(model.getGroupId()) || (model.getGroupId() == null)) && // == null in case of [inherited] value mavenProject.getArtifactId().equals(model.getArtifactId()) && (mavenProject.getVersion().equals(model.getVersion()) || (model.getVersion() == null)) && // == null in case of [inherited] value !packageSkip) {/*from w ww . j a va 2s . c o m*/ return mavenProject; } } return null; }
From source file:fr.xebia.maven.plugin.mindmap.MindmapMojo.java
License:Apache License
private void generateMindMapXML(MavenProject mavenProject, DependencyNode rootNode) throws MojoExecutionException { FileWriter fw = null;/*from ww w . j a va 2 s . co m*/ try { Properties p = new Properties(); p.setProperty("resource.loader", "class"); p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); // first, get and initialize an engine VelocityEngine ve = new VelocityEngine(); ve.init(p); // next, get the Template Template freePlaneTemplate = ve.getTemplate("MindMapTemplate.vm"); // create a context and add data VelocityContext context = new VelocityContext(); context.put("artifactId", mavenProject.getArtifactId()); context.put("sorter", new SortTool()); context.put("rootNode", rootNode); context.put("date", new SimpleDateFormat("dd/MM/yy HH:mm").format(Calendar.getInstance().getTime())); context.put("groupIdsFilteringREGEXMatch", groupIdsFilteringREGEXMatch != null ? groupIdsFilteringREGEXMatch : ""); context.put("creationTS", Calendar.getInstance().getTimeInMillis()); // now render the template fw = new FileWriter("./" + mavenProject.getGroupId() + "_" + mavenProject.getArtifactId() + "_" + mavenProject.getVersion() + ".mm"); // write the mindmap xml to disc freePlaneTemplate.merge(context, fw); } catch (Exception e) { throw new MojoExecutionException("Unable to generate mind map.", e); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { getLog().warn("Unable to properly close stream.", e); } } } }