/**
   * @see com.liferay.modulesadmin.portlet.ModulesAdminPortlet#getBundle( BundleContext,
   *     InputStream)
   */
  public Bundle getBundle(BundleContext bundleContext, InputStream inputStream)
      throws PortalException {

    try {
      if (inputStream.markSupported()) {

        // 1 megabyte is more than enough for even the largest manifest
        // file

        inputStream.mark(1024 * 1000);
      }

      JarInputStream jarInputStream = new JarInputStream(inputStream);

      Manifest manifest = jarInputStream.getManifest();

      if (inputStream.markSupported()) {
        inputStream.reset();
      }

      Attributes attributes = manifest.getMainAttributes();

      String bundleSymbolicNameAttributeValue = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);

      Parameters parameters = OSGiHeader.parseHeader(bundleSymbolicNameAttributeValue);

      Set<String> bundleSymbolicNameSet = parameters.keySet();

      Iterator<String> bundleSymbolicNameIterator = bundleSymbolicNameSet.iterator();

      String bundleSymbolicName = bundleSymbolicNameIterator.next();

      String bundleVersionAttributeValue = attributes.getValue(Constants.BUNDLE_VERSION);

      Version bundleVersion = Version.parseVersion(bundleVersionAttributeValue);

      for (Bundle bundle : bundleContext.getBundles()) {
        Version curBundleVersion = Version.parseVersion(String.valueOf(bundle.getVersion()));

        if (bundleSymbolicName.equals(bundle.getSymbolicName())
            && bundleVersion.equals(curBundleVersion)) {

          return bundle;
        }
      }

      return null;
    } catch (IOException ioe) {
      throw new PortalException(ioe);
    }
  }
예제 #2
0
  public static void testBumpIncludeFile() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("bump-included");
      project.setTrace(true);
      Version old = new Version(project.getProperty("Bundle-Version"));
      assertEquals(new Version(1, 0, 0), old);
      project.bump("=+0");

      Processor processor = new Processor();
      processor.setProperties(project.getFile("include.txt"));

      Version newv = new Version(processor.getProperty("Bundle-Version"));
      System.err.println("New version " + newv);
      assertEquals(1, newv.getMajor());
      assertEquals(1, newv.getMinor());
      assertEquals(0, newv.getMicro());
    } finally {
      IO.deleteWithException(tmp);
    }
  }
예제 #3
0
  public static void testBump() throws Exception {
    File tmp = new File("tmp-ws");
    if (tmp.exists()) IO.deleteWithException(tmp);
    tmp.mkdir();
    assertTrue(tmp.isDirectory());

    try {
      IO.copy(new File("test/ws"), tmp);
      Workspace ws = Workspace.getWorkspace(tmp);
      Project project = ws.getProject("p1");
      int size = project.getProperties().size();
      Version old = new Version(project.getProperty("Bundle-Version"));
      System.err.println("Old version " + old);
      project.bump("=+0");
      Version newv = new Version(project.getProperty("Bundle-Version"));
      System.err.println("New version " + newv);
      assertEquals(old.getMajor(), newv.getMajor());
      assertEquals(old.getMinor() + 1, newv.getMinor());
      assertEquals(0, newv.getMicro());
      assertEquals(size, project.getProperties().size());
      assertEquals("sometime", newv.getQualifier());
    } finally {
      IO.deleteWithException(tmp);
    }
  }
예제 #4
0
    @Override
    protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
      int idx = ((Integer) cellEditor.getValue()).intValue();
      String[] items = ((ComboBoxCellEditor) cellEditor).getItems();

      String selectedVersion = items[idx];
      cell.setText(selectedVersion);

      if (cell.getElement() instanceof Baseline) {
        ((Baseline) cell.getElement()).setSuggestedVersion(Version.parseVersion(selectedVersion));
      } else if (cell.getElement() instanceof Info) {
        ((Info) cell.getElement()).suggestedVersion = Version.parseVersion(selectedVersion);
      }
    }
예제 #5
0
  private int compare(Revision a, Revision b) {
    if (Arrays.equals(a._id, b._id)) return 0;

    Version va = getVersion(a);
    Version vb = getVersion(b);
    int n = va.compareTo(vb);
    if (n != 0) return n;

    if (a.created != b.created) return a.created > b.created ? 1 : -1;

    for (int i = 0; i < a._id.length; i++)
      if (a._id[i] != b._id[i]) return a._id[i] > b._id[i] ? 1 : -1;

    return 0;
  }
예제 #6
0
파일: Macro.java 프로젝트: bramk/bnd
  String version(Version version, String mask) {
    if (version == null) {
      String v = domain.getProperty("@");
      if (v == null) {
        domain.error(
            "No version specified for ${version} or ${range} and no implicit version ${@} either, mask=%s",
            mask);
        v = "0";
      }
      version = new Version(v);
    }

    StringBuilder sb = new StringBuilder();
    String del = "";

    for (int i = 0; i < mask.length(); i++) {
      char c = mask.charAt(i);
      String result = null;
      if (c != '~') {
        if (i == 3) {
          result = version.getQualifier();
        } else if (Character.isDigit(c)) {
          // Handle masks like +00, =+0
          result = String.valueOf(c);
        } else {
          int x = version.get(i);
          switch (c) {
            case '+':
              x++;
              break;
            case '-':
              x--;
              break;
            case '=':
              break;
          }
          result = Integer.toString(x);
        }
        if (result != null) {
          sb.append(del);
          del = ".";
          sb.append(result);
        }
      }
    }
    return sb.toString();
  }
  /** Created a JAR that is a bundle and that contains its dependencies */
  @Override
  public Jar executable() throws Exception {
    Collection<String> bsns = getProject().getBsns();
    if (bsns.size() != 1)
      throw new IllegalArgumentException(
          "Can only handle a single bsn for a run configuration " + bsns);
    String bsn = bsns.iterator().next();

    Jar jar = new Jar(bsn);
    String path = "aQute/remote/embedded/activator/EmbeddedActivator.class";
    URLResource resource = new URLResource(getClass().getClassLoader().getResource(path));
    jar.putResource("aQute/remote/embedded/activator/EmbeddedActivator.class", resource);

    Collection<Container> rb = getProject().getRunbundles();
    rb = Container.flatten(rb);
    Attrs attrs = new Attrs();

    for (Container c : rb) {
      if (c.getError() != null) {
        getProject().error("invalid runbundle %s", c);
      } else {
        File f = c.getFile();
        String tbsn = c.getBundleSymbolicName();
        String version = c.getVersion();
        if (version == null || !Version.isVersion(version))
          getProject()
              .warning("The version of embedded bundle %s does not have a proper version", c);

        jar.putResource("jar/" + c.getBundleSymbolicName() + ".jar", new FileResource(f));

        attrs.put(tbsn, version);
      }
    }

    Analyzer a = new Analyzer(getProject());
    a.setJar(jar);

    a.setBundleActivator(EmbeddedActivator.class.getName());
    a.setProperty("Bnd-Embedded", attrs.toString().replace(';', ','));
    Manifest manifest = a.calcManifest();
    jar.setManifest(manifest);
    getProject().getInfo(a);
    return jar;
  }
  protected void doBaselineJar(Jar jar, File output, aQute.bnd.build.Project bndProject)
      throws Exception {

    if (_reportLevelIsOff) {
      return;
    }

    ProjectBuilder projectBuilder = new ProjectBuilder(bndProject);

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

    Jar baselineJar = projectBuilder.getBaselineJar();

    try {
      if (baselineJar == null) {
        bndProject.deploy(output);

        return;
      }

      Baseline baseline = new Baseline(this, _diffPluginImpl);

      Set<Info> infos = baseline.baseline(jar, baselineJar, null);

      if (infos.isEmpty()) {
        return;
      }

      BundleInfo bundleInfo = baseline.getBundleInfo();

      Info[] infosArray = infos.toArray(new Info[infos.size()]);

      Arrays.sort(
          infosArray,
          new Comparator<Info>() {

            @Override
            public int compare(Info info1, Info info2) {
              return info1.packageName.compareTo(info2.packageName);
            }
          });

      for (Info info : infosArray) {
        String warnings = "-";

        Version newerVersion = info.newerVersion;
        Version suggestedVersion = info.suggestedVersion;

        if (suggestedVersion != null) {
          if (newerVersion.compareTo(suggestedVersion) > 0) {
            warnings = "EXCESSIVE VERSION INCREASE";
          } else if (newerVersion.compareTo(suggestedVersion) < 0) {
            warnings = "VERSION INCREASE REQUIRED";
          }
        }

        Diff packageDiff = info.packageDiff;

        Delta delta = packageDiff.getDelta();

        if (delta == Delta.REMOVED) {
          warnings = "PACKAGE REMOVED";
        } else if (delta == Delta.UNCHANGED) {
          boolean newVersionSuggested = false;

          if ((suggestedVersion.getMajor() != newerVersion.getMajor())
              || (suggestedVersion.getMicro() != newerVersion.getMicro())
              || (suggestedVersion.getMinor() != newerVersion.getMinor())) {

            warnings = "VERSION INCREASE SUGGESTED";

            newVersionSuggested = true;
          }

          if (!newVersionSuggested && !info.mismatch) {
            continue;
          }
        }

        if (((_reportLevelIsStandard || _reportOnlyDirtyPackages) && warnings.equals("-"))
            || (_reportOnlyDirtyPackages && (delta == Delta.REMOVED))) {

          continue;
        }

        doInfo(bundleInfo, info, warnings);

        if (_reportLevelIsDiff && (delta != Delta.REMOVED)) {
          doPackageDiff(packageDiff);
        }
      }
    } finally {
      if (baselineJar != null) {
        baselineJar.close();
      }

      if (_printWriter != null) {
        _printWriter.close();
      }

      projectBuilder.close();
    }
  }