Ejemplo n.º 1
0
 /** Test url includes */
 public static void testUrlIncludes2() throws IOException {
   Analyzer a = new Analyzer();
   Properties p = new Properties();
   p.setProperty("a", "1");
   p.setProperty("-include", "jar:file:jar/osgi.jar/!/META-INF/MANIFEST.MF");
   a.setProperties(p);
   assertEquals("1", a.getProperty("a"));
   assertEquals("osgi", a.getProperty("Bundle-SymbolicName"));
 }
Ejemplo n.º 2
0
 /** Test url includes props: a\ b\ c\ d last-props: end */
 public static void testUrlIncludes() throws IOException {
   Analyzer a = new Analyzer();
   Properties p = new Properties();
   p.setProperty("a", "1");
   p.setProperty("-include", "file:src/test/includeheadertest.prop");
   a.setProperties(p);
   assertEquals("1", a.getProperty("a"));
   assertEquals("end", a.getProperty("last-props"));
   assertEquals("abcd", a.getProperty("props"));
 }
Ejemplo n.º 3
0
  public static void testPrecedence() throws Exception {
    File base = IO.getFile("src/test");
    String a = "a=a.props\n";
    String b = "a=b.props\n";
    File aa = new File(base, "a.props");
    File bb = new File(base, "b.props");
    write(aa, a);
    write(bb, b);

    Analyzer analyzer = new Analyzer();
    analyzer.setBase(base);
    Properties x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, b.props");
    analyzer.setProperties(x);
    assertEquals("b.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, b.props");
    analyzer.setProperties(x);
    assertEquals("b.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "a.props, ~b.props");
    analyzer.setProperties(x);
    assertEquals("a.props", analyzer.getProperty("a")); // from org

    analyzer = new Analyzer();
    analyzer.setBase(base);
    x = new Properties();
    x.put("a", "x");
    x.put("-include", "~a.props, ~b.props");
    analyzer.setProperties(x);
    assertEquals("x", analyzer.getProperty("a")); // from org

    aa.delete();
    bb.delete();
  }
  /**
   * Check if mandatory properties are present, otherwise generate default.
   *
   * @param analyzer bnd analyzer
   * @param jar bnd jar
   * @param symbolicName bundle symbolic name
   */
  private void checkMandatoryProperties(
      final Analyzer analyzer, final Jar jar, final String symbolicName) {
    final String importPackage = analyzer.getProperty(Analyzer.IMPORT_PACKAGE);

    // imports must be generated for sure. Thats why we use BND at all.

    // if( importPackage == null || importPackage.trim().length() == 0 ) {
    analyzer.setProperty(Analyzer.IMPORT_PACKAGE, "*");
    // }

    // automatic export:
    final String exportPackage = analyzer.getProperty(Analyzer.EXPORT_PACKAGE);
    if (exportPackage == null || exportPackage.trim().length() == 0) {
      //  analyzer.setProperty( Analyzer.EXPORT_PACKAGE, analyzer.calculateExportsFromContents( jar
      // ) );
    }
    final String localSymbolicName =
        analyzer.getProperty(Analyzer.BUNDLE_SYMBOLICNAME, symbolicName);
    analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, generateSymbolicName(localSymbolicName));
  }
Ejemplo n.º 5
0
 public static void testIncludeWithProperty() throws IOException {
   File home = new File(System.getProperty("user.home"));
   File include = new File(home, "includeheadertest.txt");
   try {
     FileOutputStream fw = new FileOutputStream(include);
     fw.write("IncludeHeaderTest: yes\n\r".getBytes());
     fw.write("a: 2\n\r".getBytes());
     fw.write("b: ${a}\n\r".getBytes());
     fw.close();
     Analyzer analyzer = new Analyzer();
     analyzer.setBase(IO.getFile("src/test"));
     Properties p = new Properties();
     p.put("a", "1");
     p.put("-include", "-iamnotthere.txt, ${user.home}/includeheadertest.txt");
     analyzer.setProperties(p);
     String value = analyzer.getProperty("IncludeHeaderTest");
     assertEquals("yes", value);
     assertEquals("2", analyzer.getProperty("a"));
     assertEquals("2", analyzer.getProperty("b"));
     assertEquals(0, analyzer.getErrors().size());
   } finally {
     include.delete();
   }
 }
Ejemplo n.º 6
0
 public static void testIncludeHeader() throws IOException {
   Analyzer analyzer = new Analyzer();
   analyzer.setBase(IO.getFile("src/test"));
   Properties p = new Properties();
   p.put("a", "1");
   p.put("-include", "includeheadertest.mf, includeheadertest.prop");
   analyzer.setProperties(p);
   System.err.println(analyzer.getProperties());
   assertEquals("1", analyzer.getProperty("a"));
   assertEquals("end", analyzer.getProperty("last-props"));
   assertEquals("end", analyzer.getProperty("last-manifest"));
   assertEquals("abcd", analyzer.getProperty("manifest"));
   assertEquals("abcd", analyzer.getProperty("props"));
   assertEquals("1", analyzer.getProperty("test"));
 }
  private Manifest _calculateManifest(URL url, Manifest manifest) {
    Analyzer analyzer = new Analyzer();

    Jar jar = null;

    try {
      URLConnection urlConnection = url.openConnection();

      String fileName = url.getFile();

      if (urlConnection instanceof JarURLConnection) {
        JarURLConnection jarURLConnection = (JarURLConnection) urlConnection;

        URL jarFileURL = jarURLConnection.getJarFileURL();

        fileName = jarFileURL.getFile();
      }

      File file = new File(fileName);

      if (!file.exists() || !file.canRead()) {
        return manifest;
      }

      fileName = file.getName();

      analyzer.setJar(new Jar(fileName, file));

      jar = analyzer.getJar();

      String bundleSymbolicName = fileName;

      Matcher matcher = _bundleSymbolicNamePattern.matcher(bundleSymbolicName);

      if (matcher.matches()) {
        bundleSymbolicName = matcher.group(1);
      }

      analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, bundleSymbolicName);

      String exportPackage = _calculateExportPackage(jar);

      analyzer.setProperty(Analyzer.EXPORT_PACKAGE, exportPackage);

      analyzer.mergeManifest(manifest);

      String bundleVersion = analyzer.getProperty(Analyzer.BUNDLE_VERSION);

      if (bundleVersion != null) {
        bundleVersion = Builder.cleanupVersion(bundleVersion);

        analyzer.setProperty(Analyzer.BUNDLE_VERSION, bundleVersion);
      }

      return analyzer.calcManifest();
    } catch (Exception e) {
      _log.error(e, e);

      return manifest;
    } finally {
      if (jar != null) {
        jar.close();
      }

      analyzer.close();
    }
  }
Ejemplo n.º 8
0
 public static void testTopBottom() throws Exception {
   Analyzer analyzer = new Analyzer();
   analyzer.setProperties(IO.getFile("src/test/include.bnd/top.bnd"));
   assertEquals("0.0.257", analyzer.getProperty("Bundle-Version"));
 }