public void execute() throws MojoExecutionException {
    MavenProject project = getProject();

    if (!supportedProjectTypes.contains(project.getPackaging())) {
      getLog().info("Ignoring packaging type " + project.getPackaging());
      return;
    } else if ("NONE".equalsIgnoreCase(obrRepository)) {
      getLog().info("OBR update disabled (enable with -DobrRepository)");
      return;
    }

    Log log = getLog();
    ObrUpdate update;

    String mavenRepository = localRepository.getBasedir();

    URI repositoryXml = ObrUtils.findRepositoryXml(mavenRepository, obrRepository);
    URI obrXmlFile = ObrUtils.toFileURI(obrXml);
    URI bundleJar;

    if (null == file) {
      bundleJar = ObrUtils.findBundleJar(localRepository, project.getArtifact());
    } else {
      bundleJar = file.toURI();
    }

    Config userConfig = new Config();

    update =
        new ObrUpdate(
            repositoryXml, obrXmlFile, project, bundleJar, mavenRepository, userConfig, log);

    update.updateRepository();
  }
Exemple #2
0
  private String relativisePath(URI uri) {
    if (null != uri) {
      if (m_userConfig.isPathRelative()) {
        return ObrUtils.getRelativeURI(m_baseURI, uri).toASCIIString();
      }

      return uri.toASCIIString();
    }

    return null;
  }
Exemple #3
0
  /**
   * initialize information.
   *
   * @param repositoryXml path to the repository descriptor file
   * @param obrXml path and filename to the obr.xml file
   * @param project maven project description
   * @param mavenRepositoryPath path to the local maven repository
   * @param userConfig user information
   * @param logger plugin logger
   */
  public ObrUpdate(
      URI repositoryXml,
      URI obrXml,
      MavenProject project,
      String mavenRepositoryPath,
      Config userConfig,
      Log logger) {
    m_repositoryXml = repositoryXml;
    m_obrXml = obrXml;
    m_project = project;
    m_logger = logger;

    m_userConfig = userConfig;

    if (userConfig.isRemoteFile()) {
      m_baseURI = ObrUtils.toFileURI(mavenRepositoryPath);
    } else {
      m_baseURI = m_repositoryXml;
    }
  }
Exemple #4
0
  /**
   * update the repository descriptor file. parse the old repository descriptor file, get the old
   * reference of the bundle or determine the id for a new bundle, extract information from bindex
   * set the new information in descriptor file and save it.
   *
   * @param bundleJar path to the bundle jar file
   * @param sourceJar path to the source jar file
   * @param docJar path to the docs jar file
   * @throws MojoExecutionException if the plugin failed
   */
  public void updateRepository(URI bundleJar, URI sourceJar, URI docJar)
      throws MojoExecutionException {
    m_logger.debug(" (f) repositoryXml = " + m_repositoryXml);
    m_logger.debug(" (f) bundleJar = " + bundleJar);
    m_logger.debug(" (f) sourceJar = " + sourceJar);
    m_logger.debug(" (f) docJar = " + docJar);
    m_logger.debug(" (f) obrXml = " + m_obrXml);

    if (m_repository == null) {
      return;
    }

    // get the file size
    File bundleFile = new File(bundleJar);
    if (!bundleFile.exists()) {
      String snapshot = TIMESTAMP.matcher(bundleFile.getName()).replaceFirst("-SNAPSHOT");
      bundleFile = new File(bundleFile.getParentFile(), snapshot);
    }
    if (bundleFile.exists()) {
      URI resourceURI = m_userConfig.getRemoteBundle();
      if (null == resourceURI) {
        resourceURI = bundleJar;
        if (m_userConfig.isPathRelative()) {
          resourceURI = ObrUtils.getRelativeURI(m_baseURI, resourceURI);
        }
      }

      if (m_userConfig.isRemoteFile()) {
        m_logger.info("Deploying " + resourceURI);
      } else {
        m_logger.info("Installing " + resourceURI);
      }

      try {
        m_resourceBundle =
            (ResourceImpl) new DataModelHelperImpl().createResource(bundleFile.toURI().toURL());
        if (m_resourceBundle == null) {
          return;
        }
      } catch (IOException e) {
        throw new MojoExecutionException("Unable to load resource information", e);
      }

      m_resourceBundle.put(Resource.SIZE, String.valueOf(bundleFile.length()));
      m_resourceBundle.put(Resource.URI, resourceURI.toASCIIString());
    } else {
      m_logger.error("file doesn't exist: " + bundleJar);
      return;
    }

    // parse the obr.xml file
    if (m_obrXml != null) {
      m_logger.info("Adding " + m_obrXml);

      // URL url = getClass().getResource("/SchemaObr.xsd");
      // TODO validate obr.xml file

      // add contents to resource bundle
      parseObrXml();
    }

    String sourcePath = relativisePath(sourceJar);
    String docPath = relativisePath(docJar);

    //        m_resourceBundle.construct( m_project, bindexExtractor, sourcePath, docPath );
    //         TODO: rebuild wrt m_project

    m_repository.addResource(m_resourceBundle);
    m_repository.setLastModified(System.currentTimeMillis());
  }