Example usage for org.apache.maven.project MavenProject getModel

List of usage examples for org.apache.maven.project MavenProject getModel

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getModel.

Prototype

public Model getModel() 

Source Link

Usage

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Create new POM (based on the root POM) which lists the deployed bundles as dependencies
 * //from w w w .j  a  va2  s. c  om
 * @param bundles list of bundles to be deployed
 * @return deployment project
 * @throws MojoExecutionException
 */
private MavenProject createDeploymentProject(List bundles) throws MojoExecutionException {
    MavenProject deployProject;

    if (null == m_project.getFile()) {
        deployProject = new MavenProject();
        deployProject.setGroupId("examples");
        deployProject.setArtifactId("pax-provision");
        deployProject.setVersion("1.0-SNAPSHOT");
    } else {
        deployProject = new MavenProject(m_project);
    }

    String internalId = PomUtils.getCompoundId(deployProject.getGroupId(), deployProject.getArtifactId());
    deployProject.setGroupId(internalId + ".build");
    deployProject.setArtifactId("deployment");

    // remove unnecessary cruft
    deployProject.setPackaging("pom");
    deployProject.getModel().setModules(null);
    deployProject.getModel().setDependencies(bundles);
    deployProject.getModel().setPluginRepositories(null);
    deployProject.getModel().setReporting(null);
    deployProject.setBuild(null);

    File deployFile = new File(deployProject.getBasedir(), "runner/deploy-pom.xml");

    deployFile.getParentFile().mkdirs();
    deployProject.setFile(deployFile);

    try {
        Writer writer = StreamFactory.newXmlWriter(deployFile);
        deployProject.writeModel(writer);
        IOUtil.close(writer);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write deployment POM " + deployFile);
    }

    return deployProject;
}

From source file:org.phenotips.tool.xarimporter.ImportMojo.java

License:Open Source License

private void installExtension(Artifact artifact, XWikiContext xcontext) throws ComponentLookupException,
        InstallException, LocalExtensionRepositoryException, MojoExecutionException, ResolveException {
    ComponentManager componentManager = (ComponentManager) xcontext.get(ComponentManager.class.getName());

    LocalExtensionRepository localExtensionRepository = componentManager
            .getInstance(LocalExtensionRepository.class);
    InstalledExtensionRepository installedExtensionRepository = componentManager
            .getInstance(InstalledExtensionRepository.class);

    DefaultLocalExtension extension = new DefaultLocalExtension(null,
            new ExtensionId(artifact.getGroupId() + ':' + artifact.getArtifactId(), artifact.getBaseVersion()),
            artifact.getType());//ww w  .j  a  v  a2  s  .  co  m

    extension.setFile(artifact.getFile());

    MavenProject artifactProject = MavenUtils.getMavenProject(artifact, this.session, this.projectBuilder);

    toExtension(extension, artifactProject.getModel(), componentManager);

    if (localExtensionRepository.exists(extension.getId())) {
        localExtensionRepository.removeExtension(localExtensionRepository.getLocalExtension(extension.getId()));
    }
    LocalExtension localExtension = localExtensionRepository.storeExtension(extension);
    installedExtensionRepository.installExtension(localExtension, "wiki:xwiki", true);
}

From source file:org.phpmaven.plugin.pear.PearCreatePomMojo.java

License:Apache License

/**
 * @inheritDoc/*from w w  w. j a  v a 2s.  c om*/
 */
public void execute() throws MojoExecutionException {
    if (this.pearGroupId == null) {
        this.pearGroupId = this.channelToGroupId(this.pearChannelAlias);
    }
    if (this.pearArtifactId == null) {
        this.pearArtifactId = this.pearPackage;
    }

    final String[] versions = this.pearPackageVersion.split(",");
    final File path = this.pomTargetFile;

    if (versions.length > 1 && this.pearPackageMavenVersion != null) {
        throw new MojoExecutionException(
                "Multiple versions cannot be used with option pearPackageMavenVersion");
    }

    final File commonPom = new File(this.pomTargetFile, this.pearGroupId + "/pom.xml");
    if (!commonPom.exists()) {
        final StringBuffer modulesXmlBuffer = new StringBuffer();
        modulesXmlBuffer.append("    <modules>\n");
        modulesXmlBuffer.append("    </modules>\n");

        String pomXml = COMMON_XML_TEMPLATE.replace("${PEAR.CHANNEL}", this.pearGroupId.replace(".", "_"));
        pomXml = pomXml.replace("${TARGET.NAME}", this.pearName);
        pomXml = pomXml.replace("${REPOS.ID}", this.deployRepsitoryId);
        pomXml = pomXml.replace("${REPOS.NAME}", escapeXml(this.deployRepositoryName));
        pomXml = pomXml.replace("${REPOS.URL}", this.deployRepositoryUrl);
        pomXml = pomXml.replace("${SNAPSHOTS.ID}", this.snapshotsRepositoryId);
        pomXml = pomXml.replace("${SNAPSHOTS.NAME}", escapeXml(this.snapshotsRepositoryName));
        pomXml = pomXml.replace("${SNAPSHOTS.URL}", this.snapshotsRepositoryUrl);
        pomXml = pomXml.replace("${MODULES}", modulesXmlBuffer.toString());

        this.createPomFile(pomXml, commonPom);
    }

    try {
        final MavenProject commonProject = this.getProjectFromPom(commonPom);

        for (final String version : versions) {
            if (versions.length > 1 || this.pearPackageMavenVersion == null) {
                this.pearPackageMavenVersion = version;
            }
            this.pearPackageVersion = version;
            final String moduleName = this.pearPackage + "-" + this.pearPackageMavenVersion;
            this.pomTargetFile = new File(path, this.pearGroupId + "/" + moduleName + "/pom.xml");
            this.createThePom();
            final List<String> modules = commonProject.getModules();
            if (!modules.contains(moduleName)) {
                commonProject.getModel().addModule(moduleName);
                commonProject.writeModel(new FileWriter(commonPom));
            }
        }
    } catch (ProjectBuildingException ex) {
        throw new MojoExecutionException("Unable to read common pom " + commonPom, ex);
    } catch (IOException ex) {
        throw new MojoExecutionException("Unable to write common pom " + commonPom, ex);
    }
}

From source file:org.reficio.p2.TychoFeatureBuilder.java

License:Open Source License

public void execute() throws MojoExecutionException, IOException {
    MavenProject mp = new MavenProject();
    mp.getModel().setGroupId(this.mavenProject.getGroupId());
    mp.getModel().setArtifactId(featureId);
    mp.getModel().setVersion(featureVersion);
    mp.getModel().setPackaging("eclipse-feature");
    mp.setPluginArtifactRepositories(this.mavenProject.getPluginArtifactRepositories());
    mp.setFile(featureFile); //sets the basedir for the MavenProject
    org.eclipse.tycho.artifacts.DependencyArtifacts da = new DefaultTargetPlatform();
    mp.setContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS, da);
    mavenSession.setCurrentProject(mp);//from w  w w.  j  av  a  2  s.c o m
    executeMojo(
            plugin(groupId("org.eclipse.tycho"), artifactId("tycho-packaging-plugin"), version(TYCHO_VERSION)),
            goal("package-feature"),
            configuration(element(name("finalName"), this.featureId + "_" + this.featureVersion + ".jar"),
                    element(name("basedir"), this.featureFile.getParent()),
                    element(name("outputDirectory"), outputDirectory)),
            executionEnvironment(mp, mavenSession, buildPluginManager));

}

From source file:org.sonar.batch.InMemoryPomCreator.java

License:Open Source License

public MavenProject create() {
    File workDir = project.getWorkDir();
    String buildDirectory = workDir.getAbsolutePath() + "/target";
    Properties properties = project.getProperties();

    if (project.getBinaries().size() == 0) {
        project.addBinaryDir(buildDirectory + "/classes");
    }/*w  w  w.  ja  va 2s .  c o m*/

    final MavenProject pom = new MavenProject() {
        /**
         * This allows to specify base directory without specifying location of a pom.xml
         */
        @Override
        public File getBasedir() {
            return project.getBaseDir();
        };

        /**
         * This allows to specify project classpath (binaries + libraries).
         */
        @Override
        public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException {
            List<String> cp = new ArrayList<String>();
            cp.addAll(project.getBinaries());
            cp.addAll(project.getLibraries());
            return cp;
        }
    };

    String key = getPropertyOrDie(properties, CoreProperties.PROJECT_KEY_PROPERTY);
    String[] keys = key.split(":");
    pom.setGroupId(keys[0]);
    pom.setArtifactId(keys[1]);
    pom.setVersion(getPropertyOrDie(properties, CoreProperties.PROJECT_VERSION_PROPERTY));

    pom.setName(properties.getProperty(CoreProperties.PROJECT_NAME_PROPERTY, "Unnamed - " + key));
    pom.setDescription(properties.getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, ""));

    pom.getModel().setProperties(properties);

    pom.setArtifacts(Collections.EMPTY_SET);

    // Configure fake directories
    pom.getBuild().setDirectory(buildDirectory);
    pom.getBuild().setOutputDirectory(project.getBinaries().get(0));
    Reporting reporting = new Reporting();
    String reportingOutputDirectory = buildDirectory + "/site";
    reporting.setOutputDirectory(reportingOutputDirectory);
    pom.setReporting(reporting);

    // Configure source directories
    for (String dir : project.getSourceDirs()) {
        pom.addCompileSourceRoot(dir);
    }

    // Configure test directories
    for (String dir : project.getTestDirs()) {
        pom.addTestCompileSourceRoot(dir);
    }

    return pom;
}

From source file:org.sonar.batch.maven.MavenProjectConverter.java

License:Open Source License

@VisibleForTesting
void merge(MavenProject pom, ProjectDefinition definition) {
    String key = getSonarKey(pom);
    // IMPORTANT NOTE : reference on properties from POM model must not be saved,
    // instead they should be copied explicitly - see SONAR-2896
    definition.setProperties(pom.getModel().getProperties()).setKey(key).setVersion(pom.getVersion())
            .setName(pom.getName()).setDescription(pom.getDescription()).addContainerExtension(pom);
    guessJavaVersion(pom, definition);//from w w  w. ja  v  a  2  s  .c  om
    guessEncoding(pom, definition);
    convertMavenLinksToProperties(definition, pom);
    synchronizeFileSystem(pom, definition);
}

From source file:org.sonar.batch.MavenProjectBuilder.java

License:Open Source License

Configuration getStartupConfiguration(MavenProject pom) {
    CompositeConfiguration configuration = new CompositeConfiguration();
    configuration.addConfiguration(new SystemConfiguration());
    configuration.addConfiguration(new EnvironmentConfiguration());
    configuration.addConfiguration(new MapConfiguration(pom.getModel().getProperties()));
    return configuration;
}

From source file:org.sonar.batch.MavenProjectConverter.java

License:Open Source License

/**
 * Visibility has been relaxed for tests.
 *///from   w  ww  .j av a  2 s . c om
static ProjectDefinition convert(MavenProject pom) {
    String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId())
            .toString();
    ProjectDefinition definition = ProjectDefinition.create(pom.getModel().getProperties());
    definition.setKey(key).setVersion(pom.getVersion()).setName(pom.getName())
            .setDescription(pom.getDescription()).addContainerExtension(pom);
    synchronizeFileSystem(pom, definition);
    return definition;
}

From source file:org.sonar.batch.ProjectConfiguration.java

License:Open Source License

private void loadMavenSettings(MavenProject pom) {
    addConfiguration(new MapConfiguration(pom.getModel().getProperties()));
}

From source file:org.sonar.batch.scan.maven.MavenProjectConverter.java

License:Open Source License

@VisibleForTesting
static ProjectDefinition convert(MavenProject pom) {
    String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId())
            .toString();/*  w  ww . j  a  va2 s. c o  m*/
    ProjectDefinition definition = ProjectDefinition.create();
    // IMPORTANT NOTE : reference on properties from POM model must not be saved,
    // instead they should be copied explicitly - see SONAR-2896
    definition.setProperties(pom.getModel().getProperties()).setKey(key).setVersion(pom.getVersion())
            .setName(pom.getName()).setDescription(pom.getDescription()).addContainerExtension(pom);
    guessJavaVersion(pom, definition);
    guessEncoding(pom, definition);
    convertMavenLinksToProperties(definition, pom);
    synchronizeFileSystem(pom, definition);
    return definition;
}