View Javadoc

1   package org.lsst.ccs.utilities.jars;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.net.URL;
6   import java.util.Properties;
7   
8   /**
9    * @author bamade
10   */
11  // Date: 15/05/13
12  
13  public class MavenResources {
14      /**
15       * returns an URL for the <TT>pom.properties</TT> file linked to
16       * a maven project.
17       * <BR/>
18       * It returns an array just in case there were many jars with the same projects
19       * (an unlikely occurence!)
20       *
21       * @param org     the organisation (e.g. "org.lsst")
22       * @param project such as "org-lsst-ccs-core"
23       * @return
24       */
25      public static URL[] getPomURLs(String org, String project) {
26          String path = "/META-INF/maven/" + org + "/" + project + "/pom.properties";
27          return CommonResources.getURLsFrom(path);
28      }
29  
30      /**
31       * returns an URL for our specific <TT>$Project.maven.properties</TT> file linked to
32       * a maven project.
33       * <BR/>
34       * It returns an array just in case there were many jars with the same projects
35       * (an unlikely occurence!)
36       *
37       * @param project such as "org-lsst-ccs-core"
38       * @return
39       */
40      public static URL[] getMavenProjectURLs(String project) {
41          String path = project + ".maven.properties";
42          return CommonResources.getURLsFrom(path);
43  
44      }
45  
46      /**
47       * a facility method based on standard resource algorithm (it supposes there is only one jar
48       * for the same project in the ClassPath).
49       *
50       * @param org     the organisation (e.g. "org.lsst")
51       * @param project such as "org-lsst-ccs-core"
52       * @return
53       */
54      public static Properties getPomProperties(String org, String project) {
55          String path = "/META-INF/maven/" + org + "/" + project + "/pom.properties";
56          Properties res = new Properties();
57          try (InputStream is = MavenResources.class.getResourceAsStream(path)) {
58              if (is != null) {
59                  res.load(is);
60              }
61          } catch (IOException e) {
62              //TODO: log?
63          }
64          return res;
65      }
66  
67      /**
68       * a facility method to fetch our <TT>$Project.maven.properties</TT> based on standard resource algorithm (it supposes there is only one jar
69       * for the same project in the ClassPath).
70       *
71       * @param project such as "org-lsst-ccs-core"
72       * @return
73       */
74      public static Properties getMavenProjectProperties(String project) {
75          String path = "/" + project + ".maven.properties";
76          Properties res = new Properties();
77          try (InputStream is = MavenResources.class.getResourceAsStream(path)) {
78              if (is != null) {
79                  res.load(is);
80              }
81          } catch (IOException e) {
82              //TODO log?
83          }
84          return res;
85      }
86  
87  }