Пример #1
0
  public static void testBumpSubBuilders() 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-sub");
      project.setTrace(true);

      assertNull(project.getProperty("Bundle-Version"));

      project.bump("=+0");

      assertNull(project.getProperty("Bundle-Version"));

      for (Builder b : project.getSubBuilders()) {
        assertEquals(new Version(1, 1, 0), new Version(b.getVersion()));
      }
    } finally {
      IO.deleteWithException(tmp);
    }
  }
Пример #2
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);
    }
  }
Пример #3
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);
    }
  }
Пример #4
0
  /**
   * Create a standalone executable. All entries on the runpath are rolled out into the JAR and the
   * runbundles are copied to a directory in the jar. The launcher will see that it starts in
   * embedded mode and will automatically detect that it should load the bundles from inside. This
   * is drive by the launcher.embedded flag.
   *
   * @throws Exception
   */
  @Override
  public Jar executable() throws Exception {

    // TODO use constants in the future
    Parameters packageHeader = OSGiHeader.parseHeader(project.getProperty("-package"));
    boolean useShas = packageHeader.containsKey("jpm");
    project.trace("Useshas %s %s", useShas, packageHeader);

    Jar jar = new Jar(project.getName());

    Builder b = new Builder();
    project.addClose(b);

    if (!project.getIncludeResource().isEmpty()) {
      b.setIncludeResource(project.getIncludeResource().toString());
      b.setProperty(Constants.RESOURCEONLY, "true");
      b.build();
      if (b.isOk()) {
        jar.addAll(b.getJar());
      }
      project.getInfo(b);
    }

    List<String> runpath = getRunpath();

    Set<String> runpathShas = new LinkedHashSet<String>();
    Set<String> runbundleShas = new LinkedHashSet<String>();
    List<String> classpath = new ArrayList<String>();

    for (String path : runpath) {
      project.trace("embedding runpath %s", path);
      File file = new File(path);
      if (file.isFile()) {
        if (useShas) {
          String sha = SHA1.digest(file).asHex();
          runpathShas.add(sha + ";name=\"" + file.getName() + "\"");
        } else {
          String newPath = "jar/" + file.getName();
          jar.putResource(newPath, new FileResource(file));
          classpath.add(newPath);
        }
      }
    }

    // Copy the bundles to the JAR

    List<String> runbundles = (List<String>) getRunBundles();
    List<String> actualPaths = new ArrayList<String>();

    for (String path : runbundles) {
      project.trace("embedding run bundles %s", path);
      File file = new File(path);
      if (!file.isFile()) project.error("Invalid entry in -runbundles %s", file);
      else {
        if (useShas) {
          String sha = SHA1.digest(file).asHex();
          runbundleShas.add(sha + ";name=\"" + file.getName() + "\"");
          actualPaths.add("${JPMREPO}/" + sha);
        } else {
          String newPath = "jar/" + file.getName();
          jar.putResource(newPath, new FileResource(file));
          actualPaths.add(newPath);
        }
      }
    }

    LauncherConstants lc = getConstants(actualPaths, true);
    lc.embedded = !useShas;
    lc.storageDir = null; // cannot use local info

    final Properties p = lc.getProperties(new UTF8Properties());

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p.store(bout, "");
    jar.putResource(
        LauncherConstants.DEFAULT_LAUNCHER_PROPERTIES,
        new EmbeddedResource(bout.toByteArray(), 0L));

    Manifest m = new Manifest();
    Attributes main = m.getMainAttributes();

    for (Entry<Object, Object> e : project.getFlattenedProperties().entrySet()) {
      String key = (String) e.getKey();
      if (key.length() > 0 && Character.isUpperCase(key.charAt(0)))
        main.putValue(key, (String) e.getValue());
    }

    Instructions instructions = new Instructions(project.getProperty(Constants.REMOVEHEADERS));
    Collection<Object> result = instructions.select(main.keySet(), false);
    main.keySet().removeAll(result);

    if (useShas) {
      project.trace("Use JPM launcher");
      m.getMainAttributes().putValue("Main-Class", JPM_LAUNCHER_FQN);
      m.getMainAttributes().putValue("JPM-Classpath", Processor.join(runpathShas));
      m.getMainAttributes().putValue("JPM-Runbundles", Processor.join(runbundleShas));
      URLResource jpmLauncher = new URLResource(this.getClass().getResource("/" + JPM_LAUNCHER));
      jar.putResource(JPM_LAUNCHER, jpmLauncher);
      doStart(jar, JPM_LAUNCHER_FQN);
    } else {
      project.trace("Use Embedded launcher");
      m.getMainAttributes().putValue("Main-Class", EMBEDDED_LAUNCHER_FQN);
      m.getMainAttributes().putValue(EmbeddedLauncher.EMBEDDED_RUNPATH, Processor.join(classpath));
      URLResource embeddedLauncher =
          new URLResource(this.getClass().getResource("/" + EMBEDDED_LAUNCHER));
      jar.putResource(EMBEDDED_LAUNCHER, embeddedLauncher);
      doStart(jar, EMBEDDED_LAUNCHER_FQN);
    }
    if (project.getProperty(Constants.DIGESTS) != null)
      jar.setDigestAlgorithms(project.getProperty(Constants.DIGESTS).trim().split("\\s*,\\s*"));
    else jar.setDigestAlgorithms(new String[] {"SHA-1", "MD-5"});
    jar.setManifest(m);
    return jar;
  }
Пример #5
0
  /**
   * @return
   * @throws Exception
   * @throws FileNotFoundException
   * @throws IOException
   */
  private LauncherConstants getConstants(Collection<String> runbundles, boolean exported)
      throws Exception, FileNotFoundException, IOException {
    project.trace("preparing the aQute launcher plugin");

    LauncherConstants lc = new LauncherConstants();
    lc.noreferences = Processor.isTrue(project.getProperty(Constants.RUNNOREFERENCES));
    lc.runProperties = getRunProperties();
    lc.storageDir = getStorageDir();
    lc.keep = isKeep();
    lc.runbundles.addAll(runbundles);
    lc.trace = getTrace();
    lc.timeout = getTimeout();
    lc.services = super.getRunFramework() == SERVICES ? true : false;
    lc.activators.addAll(getActivators());
    lc.name = getProject().getName();

    if (!exported && !getNotificationListeners().isEmpty()) {
      if (listenerComms == null) {
        listenerComms = new DatagramSocket(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        new Thread(
                new Runnable() {
                  public void run() {
                    DatagramSocket socket = listenerComms;
                    DatagramPacket packet = new DatagramPacket(new byte[65536], 65536);
                    while (!socket.isClosed()) {
                      try {
                        socket.receive(packet);
                        DataInputStream dai =
                            new DataInputStream(
                                new ByteArrayInputStream(
                                    packet.getData(), packet.getOffset(), packet.getLength()));
                        NotificationType type = NotificationType.values()[dai.readInt()];
                        String message = dai.readUTF();
                        for (NotificationListener listener : getNotificationListeners()) {
                          listener.notify(type, message);
                        }
                      } catch (IOException e) {
                      }
                    }
                  }
                })
            .start();
      }
      lc.notificationPort = listenerComms.getLocalPort();
    } else {
      lc.notificationPort = -1;
    }

    try {
      // If the workspace contains a newer version of biz.aQute.launcher
      // than the version of bnd(tools) used
      // then this could throw NoSuchMethodError. For now just ignore it.
      Map<String, ? extends Map<String, String>> systemPkgs = getSystemPackages();
      if (systemPkgs != null && !systemPkgs.isEmpty())
        lc.systemPackages = Processor.printClauses(systemPkgs);
    } catch (Throwable e) {
    }

    try {
      // If the workspace contains a newer version of biz.aQute.launcher
      // than the version of bnd(tools) used
      // then this could throw NoSuchMethodError. For now just ignore it.
      String systemCaps = getSystemCapabilities();
      if (systemCaps != null) {
        systemCaps = systemCaps.trim();
        if (systemCaps.length() > 0) lc.systemCapabilities = systemCaps;
      }
    } catch (Throwable e) {
    }
    return lc;
  }
Пример #6
0
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 5;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);

    Composite repoPart = new Composite(composite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 5;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 5;
    repoPart.setLayout(gridLayout);
    GridData gd = new GridData();
    repoPart.setLayoutData(gd);

    Label label = new Label(repoPart, SWT.NONE);
    label.setText(Messages.releaseToRepo);

    String[] items = ReleaseHelper.getReleaseRepositories();
    String defaultRepo = project.getProperty(Constants.RELEASEREPO);
    int idx = 0;
    for (int i = 0; i < items.length; i++) {
      if (defaultRepo != null) {
        if (items[i].equals(defaultRepo)) {
          idx = i;
          break;
        }
      }
    }

    releaseRepoCombo = new Combo(repoPart, SWT.READ_ONLY);
    // combo.setLayout(gridLayout);
    releaseRepoCombo.setItems(items);
    releaseRepoCombo.setSize(200, 200);
    if (items.length > 0) {
      releaseRepoCombo.setText(items[idx]);
    } else {
      releaseRepoCombo.setText("");
    }

    Composite diffPart = new Composite(composite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 5;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    diffPart.setLayout(gridLayout);
    diffPart.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

    ScrolledComposite scrolled = new ScrolledComposite(diffPart, SWT.H_SCROLL | SWT.V_SCROLL);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 5;
    gridLayout.marginWidth = 10;
    gridLayout.marginHeight = 10;

    scrolled.setLayout(gridLayout);
    scrolled.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

    release.createControl(scrolled);

    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.setContent(release.getControl());
    scrolled.setMinSize(300, 300);
    scrolled.layout(true);

    return composite;
  }