Ejemplo n.º 1
0
  private void testFilePath(String path, String pattern, boolean good) throws Exception {
    Builder b = new Builder();
    try {
      b.setProperty("-includeresource", path + ";literal='x'");
      if (pattern != null) b.setProperty(Constants.INVALIDFILENAMES, pattern);

      b.build();
      if (good) assertTrue(b.check());
      else assertTrue(b.check("Invalid file/directory"));
    } finally {
      b.close();
    }
  }
Ejemplo n.º 2
0
  public static void testnativeCode() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("-resourceonly", "true");
    b.setProperty("Include-Resource", "native/win32/NTEventLogAppender-1.2.dll;literal='abc'");
    b.setProperty(
        "Bundle-NativeCode",
        "native/win32/NTEventLogAppender-1.2.dll; osname=Win32; processor=x86");
    b.build();
    Verifier v = new Verifier(b);

    v.verifyNative();
    System.err.println(v.getErrors());
    assertEquals(0, v.getErrors().size());
    v.close();
    b.close();
  }
Ejemplo n.º 3
0
  private File create(String bsn, Version v) throws Exception {
    String name = bsn + "-" + v;
    Builder b = new Builder();
    b.setBundleSymbolicName(bsn);
    b.setBundleVersion(v);
    b.setProperty("Random", random++ + "");
    b.setProperty("-resourceonly", true + "");
    b.setIncludeResource("foo;literal='foo'");
    Jar jar = b.build();
    assertTrue(b.check());

    File file = IO.getFile(tmp, name + ".jar");
    file.getParentFile().mkdirs();
    jar.updateModified(System.currentTimeMillis(), "Force it to now");
    jar.write(file);
    b.close();
    return file;
  }
Ejemplo n.º 4
0
  @Override
  protected void doExecute() throws Exception {
    aQute.bnd.build.Project bndProject = getBndProject();

    Builder builder = new Builder(bndProject);

    builder.setClasspath(_classpathFiles.toArray(new File[_classpathFiles.size()]));
    builder.setPedantic(isPedantic());
    builder.setProperties(_file);
    builder.setSourcepath(new File[] {_sourcePath});

    Jar[] jars = builder.builds();

    // Report both task failures and bnd build failures

    boolean taskFailed = report();
    boolean bndFailed = report(builder);

    // Fail this build if failure is not ok and either the task failed or
    // the bnd build failed

    if (taskFailed || bndFailed) {
      throw new BuildException(
          "bnd failed", new org.apache.tools.ant.Location(_file.getAbsolutePath()));
    }

    for (Jar jar : jars) {
      String bsn = jar.getName();

      File outputFile = _outputPath;

      if (_outputPath.isDirectory()) {
        String path = builder.getProperty("-output");

        if (path != null) {
          outputFile = getFile(_outputPath, path);
        } else {
          outputFile = getFile(_outputPath, bsn + ".jar");
        }
      }

      if (!outputFile.exists() || (outputFile.lastModified() <= jar.lastModified())) {

        jar.write(outputFile);

        Map<String, Resource> resources = jar.getResources();

        log(jar.getName() + " (" + outputFile.getName() + ") " + resources.size());

        doBaselineJar(jar, outputFile, bndProject);
      } else {
        Map<String, Resource> resources = jar.getResources();

        log(
            jar.getName()
                + " ("
                + outputFile.getName()
                + ") "
                + resources.size()
                + " (not modified)");
      }

      report();

      jar.close();
    }

    builder.close();
  }
Ejemplo n.º 5
0
  @SuppressWarnings("cast")
  private void executeBackwardCompatible() throws BuildException {
    try {
      if (files == null) throw new BuildException("No files set");

      if (eclipse) {
        File project = getProject().getBaseDir();
        EclipseClasspath cp = new EclipseClasspath(this, project.getParentFile(), project);
        classpath.addAll(cp.getClasspath());
        classpath.addAll(cp.getBootclasspath());
        sourcepath.addAll(cp.getSourcepath());
        // classpath.add(cp.getOutput());
        if (report()) throw new BuildException("Errors during Eclipse Path inspection");
      }

      if (output == null) output = getProject().getBaseDir();

      for (Iterator<File> f = files.iterator(); f.hasNext(); ) {
        File file = f.next();
        Builder builder = new Builder();

        builder.setPedantic(isPedantic());
        if (file.exists()) {
          // Do nice property calculations
          // merging includes etc.
          builder.setProperties(file);
        }

        // get them and merge them with the project
        // properties, if the inherit flag is specified
        if (inherit) {
          Properties projectProperties = new UTF8Properties();
          @SuppressWarnings("unchecked")
          Hashtable<Object, Object> antProps = getProject().getProperties();
          projectProperties.putAll(antProps);
          projectProperties.putAll(builder.getProperties());
          builder.setProperties(projectProperties);
        }

        builder.setClasspath(toFiles(classpath, "classpath"));
        builder.setSourcepath(toFiles(sourcepath, "sourcepath"));
        Jar jars[] = builder.builds();

        // Report both task failures and bnd build failures.
        boolean taskFailed = report();
        boolean bndFailed = report(builder);

        // Fail this build if failure is not ok and either the task
        // failed or the bnd build failed.
        if (!failok && (taskFailed || bndFailed)) {
          throw new BuildException(
              "bnd failed", new org.apache.tools.ant.Location(file.getAbsolutePath()));
        }

        for (int i = 0; i < jars.length; i++) {
          Jar jar = jars[i];
          String bsn = jar.getName();

          File base = file.getParentFile();
          File output = this.output;

          String path = builder.getProperty("-output");

          if (output == null) {
            if (path == null) output = getFile(base, bsn + ".jar");
            else {
              output = getFile(base, path);
            }
          } else if (output.isDirectory()) {
            if (path == null) output = getFile(this.output, bsn + ".jar");
            else output = getFile(this.output, path);
          } else if (output.isFile()) {
            if (files.size() > 1) messages.GotFileNeedDir_(output.getAbsoluteFile());
          }

          String msg = "";
          if (!output.exists() || output.lastModified() <= jar.lastModified()) {
            jar.write(output);
          } else {
            msg = "(not modified)";
          }
          trace("%s (%s) %s %s", jar.getName(), output.getName(), jar.getResources().size(), msg);
          report();
          jar.close();
        }
        builder.close();
      }
    } catch (Exception e) {
      // if (exceptions)
      e.printStackTrace();
      if (!failok) throw new BuildException("Failed to build jar file: ", e);
    }
  }