public void testDependOnAutoload() throws Exception {
    ModuleManager mgr = Main.getModuleSystem().getManager();
    mgr.mutexPrivileged().enterWriteAccess();
    try {
      Module m1;
      String mf =
          "Bundle-SymbolicName: org.require.autoload\n"
              + "Bundle-Version: 33.0.3\n"
              + "Bundle-ManifestVersion: 2\n"
              + "Require-Bundle: org.openide.compat\n\n";
      /*
      mf = "OpenIDE-Module: org.require.autoload\n" +
          "OpenIDE-Module-Module-Dependencies: org.openide.compat\n\n";
      /**/
      File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf);
      m1 = mgr.create(jj1, null, false, false, false);

      CharSequence log = Log.enable("org.netbeans.core.modules", Level.WARNING);
      mgr.enable(m1);

      assertTrue("OSGi module is now enabled", m1.isEnabled());

      Class<?> wl = m1.getClassLoader().loadClass("org.openide.util.WeakListener");
      assertNotNull("Weak listener found", wl);

      Module compat = mgr.get("org.openide.compat");
      assertTrue("Compat module is turned on too", compat.isEnabled());
    } finally {
      mgr.mutexPrivileged().exitWriteAccess();
    }
  }
Esempio n. 2
0
  /**
   * Enables logging for given logger name and given severity. Everything logged to the object is
   * going to go to the returned CharSequence object which can be used to check the content or
   * converted <code>toString</code>.
   *
   * <p>The logging stops when the returned object is garbage collected.
   *
   * @param loggerName the name to capture logging for
   * @param level the level of details one wants to get
   * @return character sequence which can be check or converted to string
   * @since 1.27
   */
  public static CharSequence enable(String loggerName, Level level) {
    IL il = new IL(false);
    class MyPs extends PrintStream implements CharSequence {
      private ByteArrayOutputStream os;

      public MyPs() {
        this(new ByteArrayOutputStream());
      }

      private MyPs(ByteArrayOutputStream arr) {
        super(arr);
        os = arr;
      }

      public int length() {
        return toString().length();
      }

      public char charAt(int index) {
        return toString().charAt(index);
      }

      public CharSequence subSequence(int start, int end) {
        return toString().subSequence(start, end);
      }

      @Override
      public String toString() {
        return os.toString();
      }
    }

    Logger l = Logger.getLogger(loggerName);
    if (l.getLevel() == null || l.getLevel().intValue() > level.intValue()) {
      l.setLevel(level);
    }
    MyPs ps = new MyPs();
    Log log = new Log(l, ps);
    log.setLevel(level);
    l.addHandler(log);
    return ps;
  }
Esempio n. 3
0
  private PrintStream getLog() {
    if (log != null) {
      PrintStream ps = log.get();
      if (ps == null) {
        // gc => remove the handler
        setLevel(Level.OFF);
        logger.removeHandler(this);
      }

      return ps;
    }

    NbTestCase c = current;
    Runnable off = Log.internalLog();
    try {
      return c == null ? System.err : c.getLog();
    } finally {
      off.run();
    }
  }
 public void testRenderInvalidDataObject() throws IOException {
   JList list = new JList();
   Object wr = new WeakReference<Object>(obj);
   int index = 0;
   boolean isSelected = false;
   boolean cellHasFocus = false;
   obj.delete();
   CharSequence log = Log.enable("", Level.WARNING);
   ObjectListRenderer instance = new ObjectListRenderer();
   Component result =
       instance.getListCellRendererComponent(list, wr, index, isSelected, cellHasFocus);
   if (!(result instanceof JLabel)) {
     fail("Not JLabel: " + result);
   }
   JLabel l = (JLabel) result;
   assertEquals("Name", obj.getName(), l.getText());
   if (log.length() > 0) {
     fail("There should be no warnings!\n" + log);
   }
 }