Esempio n. 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();
     }
   }
 }
Esempio n. 2
0
  private void initialize() {
    if (currentModel == null) {
      try {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        FileInputStream stream = new FileInputStream(getUnderlyingResourceObject());
        if (stream.available() > 0) {
          currentModel = reader.read(stream);
        }
        stream.close();

        currentModel.setPomFile(getUnderlyingResourceObject());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
Esempio n. 3
0
  private void initialize() {
    if (isStale() || currentModel == null) {
      try (InputStream stream = getResourceInputStream()) {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        currentModel = reader.read(stream);
        currentModel.setPomFile(getUnderlyingResourceObject());

        // FORGE-2273: Making properties sortable
        SortedProperties sortedProps = new SortedProperties();
        sortedProps.putAll(currentModel.getProperties());
        currentModel.setProperties(sortedProps);
      } catch (Exception e) {
        throw new RuntimeException(e);
      } finally {
        refresh();
      }
    }
  }
Esempio n. 4
0
  public void importProjects(
      IProgressMonitor monitor,
      File pomFile,
      String projectName,
      String groupId,
      String artifactId,
      String version)
      throws CoreException {

    IProjectConfigurationManager manager = MavenPlugin.getProjectConfigurationManager();
    ProjectImportConfiguration config = new ProjectImportConfiguration();
    Collection<MavenProjectInfo> infos = new ArrayList<MavenProjectInfo>();
    Model model = new Model();
    model.setGroupId(groupId);
    model.setArtifactId(artifactId);
    model.setVersion(version);
    model.setPomFile(pomFile);
    MavenProjectInfo info = new MavenProjectInfo(projectName, pomFile, model, null);
    infos.add(info);

    manager.importProjects(infos, config, monitor);
  }