コード例 #1
0
  private static Dependency parseDependency_1_2_2(File f) throws JAXBException {
    final JAXBContext context = JAXBContext.newInstance(Versions.class);
    final Unmarshaller unmarshaller = context.createUnmarshaller();

    final Versions versions = (Versions) unmarshaller.unmarshal(f);

    final Dependency dependency = new Dependency();
    dependency.setCoordinates(versions.getCoordinates());
    dependency.setScm(versions.getScm());

    if (versions.getDependencies() != null)
      for (Dependency d : versions.getDependencies()) dependency.addDependency(d);

    return dependency;
  }
コード例 #2
0
  private void createVersionInfoFile(
      final String groupId,
      final String artifactId,
      final String version,
      Properties versionInfo,
      List<Dependency> dependencies,
      OutputStream os)
      throws MojoExecutionException, JAXBException {
    try {

      final String connectionString =
          "scm:perforce:"
              + versionInfo.getProperty("port")
              + ":"
              + getDepotPath(versionInfo.getProperty("depotpath"));

      final Versions versions = new Versions();

      for (final Dependency dep : dependencies) versions.addDependency(dep);

      final SCM scm = new SCM();
      scm.setConnection(connectionString);
      scm.setRevision(versionInfo.getProperty("changelist"));

      final Coordinates coordinates = new Coordinates();
      coordinates.setGroupId(groupId);
      coordinates.setArtifactId(artifactId);
      coordinates.setVersion(version);

      versions.setScm(scm);
      versions.setCoordinates(coordinates);

      final JAXBContext context = JAXBContext.newInstance(Versions.class);

      final Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      marshaller.setProperty(
          Marshaller.JAXB_SCHEMA_LOCATION,
          "urn:xml.sap.com:XCodePlugin:VersionInfo"
              + " "
              + NEXUS_URL
              + "/content/repositories/"
              + SCHEMA_REPOSITORY
              + "/"
              + SCHEMA_GROUP_ID.replace(".", "/")
              + "/"
              + SCHEMA_ARTIFACT_ID
              + "/"
              + SCHEMA_VERSION
              + "/"
              + SCHEMA_ARTIFACT_ID
              + "-"
              + SCHEMA_VERSION
              + ".xsd");

      final ByteArrayOutputStream byteOs = new ByteArrayOutputStream();

      marshaller.marshal(versions, byteOs);

      final byte[] b = byteOs.toByteArray();

      DomUtils.validateDocument(
          DocumentBuilderFactory.newInstance()
              .newDocumentBuilder()
              .parse(new ByteArrayInputStream(b)));

      IOUtils.write(b, os);
    } catch (ParserConfigurationException e) {
      throw new MojoExecutionException("Cannot create versions.xml.", e);
    } catch (IOException e) {
      throw new MojoExecutionException("Cannot create versions.xml.", e);
    } catch (SAXException e) {
      throw new MojoExecutionException("Cannot create versions.xml.", e);
    }
  }