List of usage examples for org.apache.maven.project MavenProject setDistributionManagement
public void setDistributionManagement(DistributionManagement distributionManagement)
From source file:io.sundr.maven.GenerateBomMojo.java
License:Apache License
/** * Returns the generated {@link org.apache.maven.project.MavenProject} to build. * This version of the project contains all the stuff needed for building (parents, profiles, properties etc). * * @param project The source {@link org.apache.maven.project.MavenProject}. * @param config The {@link io.sundr.maven.BomConfig}. * @return The build {@link org.apache.maven.project.MavenProject}. *//*from w ww . j av a 2 s . c o m*/ private static MavenProject toBuild(MavenProject project, BomConfig config) { File outputDir = new File(project.getBuild().getOutputDirectory()); File bomDir = new File(outputDir, config.getArtifactId()); File generatedBom = new File(bomDir, BOM_NAME); MavenProject toBuild = project.clone(); //we want to avoid recursive "generate-bom". toBuild.setExecutionRoot(false); toBuild.setFile(generatedBom); toBuild.getModel().setPomFile(generatedBom); toBuild.setModelVersion(project.getModelVersion()); toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(), project.getArtifact().getScope(), project.getArtifact().getType(), project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler())); toBuild.setParent(project.getParent()); toBuild.getModel().setParent(project.getModel().getParent()); toBuild.setGroupId(project.getGroupId()); toBuild.setArtifactId(config.getArtifactId()); toBuild.setVersion(project.getVersion()); toBuild.setPackaging("pom"); toBuild.setName(config.getName()); toBuild.setDescription(config.getDescription()); toBuild.setUrl(project.getUrl()); toBuild.setLicenses(project.getLicenses()); toBuild.setScm(project.getScm()); toBuild.setDevelopers(project.getDevelopers()); toBuild.setDistributionManagement(project.getDistributionManagement()); toBuild.getModel().setProfiles(project.getModel().getProfiles()); //We want to avoid having the generated stuff wiped. toBuild.getProperties().put("clean.skip", "true"); toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath()); toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath()); for (String key : config.getProperties().stringPropertyNames()) { toBuild.getProperties().put(key, config.getProperties().getProperty(key)); } return toBuild; }
From source file:org.wso2.maven.capp.mojo.AbstractPOMGenMojo.java
License:Open Source License
protected void processArtifacts(List<Artifact> artifacts) throws MojoExecutionException { if (artifacts.isEmpty()) { if (getLog().isDebugEnabled()) { getLog().debug(System.currentTimeMillis() + " Artifacts list is empty. Nothing to process"); }/*from w ww. jav a 2 s. co m*/ File projectLocation = new File(getOutputLocation() + ""); projectLocation.mkdirs(); setProjectLocation(projectLocation); getMavenModuleProject(); } else { if (getLog().isDebugEnabled()) { getLog().info( new Time(System.currentTimeMillis()) + " Artifacts list is not empty. Start processing"); } for (Artifact artifact : artifacts) { if (artifact.getType().equalsIgnoreCase(getArtifactType())) { if (getLog().isDebugEnabled()) { getLog().debug( new Time(System.currentTimeMillis()) + " Creating maven project for artifact "); } getLog().info("Creating maven project for artifact " + artifact.getName() + ":" + artifact.getVersion() + "..."); if (getLog().isDebugEnabled()) { getLog().debug( new Time(System.currentTimeMillis()) + " Trying to generate the Maven Project..."); } getLog().info("\tgenerating maven project..."); File projectLocation = new File(getOutputLocation() + File.separator + getArtifactPostFix(), artifact.getName()); projectLocation.mkdirs(); setProjectLocation(projectLocation); // This will be null if the artifact is referencing to a // workspace project. MavenProject artifactMavenProject = createMavenProjectForCappArtifact(artifact, artifacts, projectLocation); artifactMavenProject.setDistributionManagement(project.getDistributionManagement()); if (getLog().isDebugEnabled()) { getLog().debug( new Time(System.currentTimeMillis()) + " Maven Project generation completed"); } if (artifactMavenProject != null) { if (getLog().isDebugEnabled()) { getLog().debug( new Time(System.currentTimeMillis()) + " Generated Maven project is not null"); } try { if (getLog().isDebugEnabled()) { getLog().debug(new Time(System.currentTimeMillis()) + " copying resources..."); } getLog().info("\tcopying resources..."); String artifactAsMavenModule = CAppMavenUtils .getMavenModuleRelativePath(getModuleProject(), projectLocation); List existingModules = getMavenModuleProject().getModules(); if (!existingModules.contains(artifactAsMavenModule)) { existingModules.add(artifactAsMavenModule); } if (getLog().isDebugEnabled()) { getLog().debug(new Time(System.currentTimeMillis()) + " Module list is updated with new module."); } // Repository repo = new Repository(); // repo.setUrl("http://dist.wso2.org/maven2"); // repo.setId("wso2-maven2-repository-1"); // artifactMavenProject.getModel().addRepository(repo); // artifactMavenProject.getModel() // .addPluginRepository(repo); //Add repositories defined in the parent project to the generated poms. List repositories = project.getRepositories(); artifactMavenProject.getModel().getRepositories().addAll(repositories); artifactMavenProject.getModel().getPluginRepositories().addAll(repositories); if (getLog().isDebugEnabled()) { getLog().debug(new Time(System.currentTimeMillis()) + " Maven project successfully updated with Repositories"); } CAppMavenUtils.saveMavenProject(artifactMavenProject, new File(projectLocation, "pom.xml")); CAppMavenUtils.saveMavenProject(getMavenModuleProject(), getModuleProject()); if (getLog().isDebugEnabled()) { getLog().debug(new Time(System.currentTimeMillis()) + " Maven projects successfully saved"); } copyResources(artifactMavenProject, projectLocation, artifact); } catch (Exception e) { throw new MojoExecutionException( "Error creating maven project for artifact '" + artifact.getName() + "'", e); } } } } } }