Java Code Examples for org.apache.maven.model.Model#setPomFile()

The following examples show how to use org.apache.maven.model.Model#setPomFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenModelBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Model getModel(ModelBuildingRequest request) {
    Model requestModel = request.getRawModel();
    if (requestModel == null) {
        if (request.getModelSource() != null) {
            try {
                requestModel = ModelUtils.readModel(request.getModelSource().getInputStream());
                request.setRawModel(requestModel);
                if (request.getPomFile() != null) {
                    requestModel.setPomFile(request.getPomFile());
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return requestModel;
}
 
Example 2
Source File: TestEnvironmentUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static String getMavenPropertyVersionFor(String key) {
  // Maven compile uses a jar, and is in target
  String basePath = Paths.get("").toAbsolutePath().toString();
  if (basePath.endsWith("target")) {
    basePath = basePath.replace("target/", "");
  }

  String pomfile = basePath + "/../../pom.xml";
  Model model = null;
  MavenXpp3Reader mavenreader = new MavenXpp3Reader();
  try {
    FileReader reader = new FileReader(pomfile);
    model = mavenreader.read(reader);
    model.setPomFile(new File(pomfile));
  } catch (Exception ex) {
    throw new IllegalStateException("Can't find the pom.xml file. basePath=" + basePath + " pomFile=" + pomfile);
  }

  MavenProject project = new MavenProject(model);
  Properties properties = project.getProperties();
  String value = (String) properties.get(key);
  return value;
}
 
Example 3
Source File: AbstractSundrioMojo.java    From sundrio with Apache License 2.0 6 votes vote down vote up
MavenProject readProject(File pomFile) throws IOException {
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    FileReader fileReader = null;
    try {
        fileReader = new FileReader(pomFile);
        Model model = mavenReader.read(fileReader);
        model.setPomFile(pomFile);
        MavenProject project = new MavenProject(model);
        project.setFile(pomFile);
        project.setArtifact(createArtifact(pomFile, model.getGroupId(), model.getArtifactId(), model.getVersion(), "compile", model.getPackaging(), ""));
        return project;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (fileReader != null) {
            fileReader.close();
        }
    }
}
 
Example 4
Source File: MavenUtilTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private MavenProject loadMavenProjectFromPom() throws IOException, XmlPullParserException {
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    File pomfile = new File(getClass().getResource("/util/test-pom.xml").getFile());
    final FileReader reader = new FileReader(pomfile);
    final Model model  = mavenreader.read(reader);
    model.setPomFile(pomfile);
    model.getBuild().setOutputDirectory(temporaryFolder.newFolder("outputDirectory").getAbsolutePath());
    model.getBuild().setDirectory(temporaryFolder.newFolder("build").getAbsolutePath());
    return new MavenProject(model);
}
 
Example 5
Source File: AddExtensionMojoTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void init() throws IOException {
    mojo = getMojo();
    mojo.project = new MavenProject();
    mojo.project.setPomFile(OUTPUT_POM);
    mojo.project.setFile(OUTPUT_POM);
    Model model = new Model();
    mojo.project.setModel(model);
    mojo.project.setOriginalModel(model);
    FileUtils.copyFile(MIN_POM, OUTPUT_POM);
    model.setPomFile(OUTPUT_POM);
}
 
Example 6
Source File: LocalProject.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static final Model readModel(Path pom) throws BootstrapMavenException {
    try {
        final Model model = ModelUtils.readModel(pom);
        model.setPomFile(pom.toFile());
        return model;
    } catch (IOException e) {
        throw new BootstrapMavenException("Failed to read " + pom, e);
    }
}
 
Example 7
Source File: MavenEmbedder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void normalizePath(Model model) {
    if (model != null) {
        File f = model.getPomFile();
        if (f != null) {
            model.setPomFile(FileUtil.normalizeFile(f));
        }
    }
}
 
Example 8
Source File: MavenUtil.java    From maven-git-versioning-extension with MIT License 5 votes vote down vote up
/**
 * Read model from pom file
 *
 * @param pomFile pomFile
 * @return Model
 * @throws IOException IOException
 */
static Model readModel(File pomFile) throws IOException {
    try (InputStream inputStream = new FileInputStream(pomFile)) {
        Model model = new MavenXpp3Reader().read(inputStream);
        model.setPomFile(pomFile);
        return model;
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: GitVersioningModelProcessor.java    From maven-git-versioning-extension with MIT License 4 votes vote down vote up
public Model processModel(Model projectModel, Map<String, ?> options) throws IOException {
    if (this.disabled) {
        return projectModel;
    }

    final Source pomSource = (Source) options.get(ModelProcessor.SOURCE);
    if (pomSource != null) {
        projectModel.setPomFile(new File(pomSource.getLocation()));
    }

    try {
        if (!initialized) {
            logger.info("");
            String extensionId = BuildProperties.projectArtifactId() + ":" + BuildProperties.projectVersion();
            logger.info(extensionLogFormat(extensionId));

            try {
                mavenSession = sessionScope.scope(Key.get(MavenSession.class), null).get();
            } catch (OutOfScopeException ex) {
                logger.warn("skip - no maven session present");
                disabled = true;
                return projectModel;
            }

            if (parseBoolean(getCommandOption(OPTION_NAME_DISABLE))) {
                logger.info("skip - versioning is disabled");
                disabled = true;
                return projectModel;
            }

            File executionRootDirectory = new File(mavenSession.getRequest().getBaseDirectory());
            logger.debug("executionRootDirectory: " + executionRootDirectory.toString());

            mvnDirectory = findMvnDirectory(executionRootDirectory);
            logger.debug("mvnDirectory: " + mvnDirectory.toString());

            String configFileName = BuildProperties.projectArtifactId() + ".xml";
            File configFile = new File(mvnDirectory, configFileName);
            logger.debug("configFile: " + configFile.toString());
            config = loadConfig(configFile);

            gitDirectory = findGitDir(executionRootDirectory);
            if (gitDirectory == null || !gitDirectory.exists()) {
                logger.warn("skip - project is not part of a git repository");
                disabled = true;
                return projectModel;
            }

            logger.debug("gitDirectory: " + gitDirectory.toString());

            gitVersionDetails = getGitVersionDetails(config, executionRootDirectory);

            logger.info("Adjusting project models...");
            logger.info("");
            initialized = true;
        }

        return processModel(projectModel);
    } catch (Exception e) {
        throw new IOException("Git Versioning Model Processor", e);
    }
}
 
Example 10
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void set( Model model, File value )
{
    model.setPomFile( value );
}