示例#1
0
 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();
     }
   }
 }
 private static MavenProject createProject(String artifactId, String version, File file) {
   Model model = new Model();
   model.setGroupId("groupId");
   model.setArtifactId(artifactId);
   model.setVersion(version);
   MavenProject project = new MavenProject(model);
   project.setFile(file);
   return project;
 }
 private MavenProject createMavenProject(String projectRootPath) throws IOException {
   File projectFile = new File(projectRootPath + "/pom.xml").getAbsoluteFile();
   MavenProject project = new MavenProject();
   project.setFile(projectFile);
   project
       .getBuild()
       .setOutputDirectory(
           projectFile
               .getParentFile()
               .toPath()
               .resolve("target/classes")
               .toFile()
               .getCanonicalPath());
   Resource resource = new Resource();
   resource.setDirectory(new File(projectRootPath + "/src/main/resources").getAbsolutePath());
   project.getResources().add(resource);
   return project;
 }