Java Code Examples for org.openide.util.NbBundle#setBranding()

The following examples show how to use org.openide.util.NbBundle#setBranding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StampsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testBrandingChecked() throws Exception {
    Stamps s = Stamps.getModulesJARs();
    ByteBuffer first = s.asByteBuffer("branding.cache");
    assertNull("No cache yet", first);
    
    s.scheduleSave(new SaveByte(), "branding.cache", false);
    s.waitFor(false);

    reset();
    s = Stamps.getModulesJARs();
    ByteBuffer snd = s.asByteBuffer("branding.cache");
    assertNotNull("Cache found", snd);

    reset();
    NbBundle.setBranding("my_perfect_branding");
    
    s = Stamps.getModulesJARs();
    ByteBuffer third = s.asByteBuffer("branding.cache");
    assertNull("Branding changed no cache found", third);
}
 
Example 2
Source File: NbInstallerTest3.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Test #21173/#23595: overriding layers by branding. */
public void testBrandingLayerOverrides() throws Exception {
    Main.getModuleSystem ();
    final MockEvents ev = new MockEvents();
    NbInstaller installer = new NbInstaller(ev);
    ModuleManager mgr = new ModuleManager(installer, ev);
    installer.registerManager(mgr);
    mgr.mutexPrivileged().enterWriteAccess();
    try {
        String orig = NbBundle.getBranding();
        NbBundle.setBranding("foo");
        try {
            Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false);
            assertEquals(Collections.EMPTY_SET, m1.getProblems());
            mgr.enable(m1);
            assertEquals("special contents", slurp("foo/file1.txt"));
            assertEquals(null, slurp("foo/file2.txt"));
            mgr.disable(m1);
            mgr.delete(m1);
        } finally {
            NbBundle.setBranding(orig);
        }
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
}
 
Example 3
Source File: ModuleManagerPersistanceTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    
    File home = new File(getWorkDir(), "home");
    final File configModules = new File(new File(home, "config"), "Modules");
    configModules.mkdirs();
    new File(configModules, "a-b-c.xml").createNewFile();
    File moduleDir = new File(home, "modules");
    moduleDir.mkdirs();
    System.setProperty("netbeans.home", home.getPath());
    
    File ud = new File(getWorkDir(), "ud");
    ud.mkdirs();
    System.setProperty("netbeans.user", ud.getPath());
    
    Locale.setDefault(Locale.ENGLISH);
    NbBundle.setBranding("nb");
    
    Thread.sleep(100);
    
    
    Stamps.main("clear");
    sampleModule = new File(moduleDir, "m1.jar");
    mgr = createModuleManager();
    mgr.shutDown();
    Stamps.getModulesJARs().shutdown();
    assertTrue("Cache has been created", Stamps.getModulesJARs().exists("all-manifests.dat"));
    Stamps.main("init");
}
 
Example 4
Source File: ModuleManagerPersistanceLocaleTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    
    File home = new File(getWorkDir(), "home");
    final File configModules = new File(new File(home, "config"), "Modules");
    configModules.mkdirs();
    new File(configModules, "a-b-c.xml").createNewFile();
    File moduleDir = new File(home, "modules");
    moduleDir.mkdirs();
    System.setProperty("netbeans.home", home.getPath());
    
    File ud = new File(getWorkDir(), "ud");
    ud.mkdirs();
    System.setProperty("netbeans.user", ud.getPath());
    
    Locale.setDefault(Locale.ENGLISH);
    NbBundle.setBranding("nb");
    
    Thread.sleep(100);
    
    
    Stamps.main("clear");
    sampleModule = new File(moduleDir, "m1.jar");
    mgr = createModuleManager();
    mgr.shutDown();
    Stamps.getModulesJARs().shutdown();
    assertTrue("Cache has been created", Stamps.getModulesJARs().exists("all-manifests.dat"));
    Stamps.main("init");
}
 
Example 5
Source File: NbURLStreamHandlerFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void checkNbresLoc(String base, String ext) throws Exception {
    String path = base + ext;
    String type = ext.equals(".html") ? "text/html" : null;
    URL u = new URL("nbresloc:" + path);
    // Should initially be getting an unlocalized version:
    NbBundle.setBranding(null);
    Locale.setDefault(Locale.US);
    assertEquals(path, suck(u));
    assertEquals(type, contentType(u));
    assertEquals(path.length(), contentLength(u));
    // Make sure branding works.
    NbBundle.setBranding("foo");
    path = base + "_foo" + ext;
    assertEquals(path, suck(u));
    assertEquals(type, contentType(u));
    assertEquals(path.length(), contentLength(u));
    // Check unbranded but localized resources.
    NbBundle.setBranding(null);
    Locale.setDefault(Locale.JAPAN);
    path = base + "_ja" + ext;
    assertEquals(path, suck(u));
    assertEquals(type, contentType(u));
    assertEquals(path.length(), contentLength(u));
    // Check both together.
    NbBundle.setBranding("foo");
    path = base + "_foo_ja" + ext;
    assertEquals(path, suck(u));
    assertEquals(type, contentType(u));
    assertEquals(path.length(), contentLength(u));
}
 
Example 6
Source File: InstalledFileLocatorImplDirTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    scratch = new File(getWorkDir(), "install");
    nbhome = new File(scratch, "nbhome");
    touch(file(nbhome, "a/b"));
    touch(file(nbhome, "a/c"));
    touch(file(nbhome, "d"));
    touch(file(nbhome, "e/f/g"));
    touch(file(nbhome, "loc/x.html"));
    touch(file(nbhome, "loc/x_ja.html"));
    touch(file(nbhome, "loc/x_foo.html"));
    touch(file(nbhome, "loc/x_foo_ja.html"));
    touch(file(nbhome, "loc/y.html"));
    touch(file(nbhome, "h_ja"));
    nbuser = new File(getWorkDir(), "nbuser");
    touch(file(nbuser, "a/b"));
    nbdir1 = new File(scratch, "nbdir1");
    touch(file(nbdir1, "e/f/g"));
    nbdir2 = new File(scratch, "nbdir2");
    touch(file(nbdir2, "h"));
    touch(file(nbdir2, "loc/y_foo.html"));
    File nbdirx = new File(scratch, "nbdirx"); // nonexistent dir
    System.setProperty("netbeans.home", nbhome.getAbsolutePath());
    System.setProperty("netbeans.user", nbuser.getAbsolutePath());
    System.setProperty("netbeans.dirs",
        nbdir1.getAbsolutePath() + File.pathSeparatorChar +
        nbdir2.getAbsolutePath() + File.pathSeparatorChar +
        // Useless trailing separator intentional:
        nbdirx.getAbsolutePath() + File.pathSeparatorChar);
    NbBundle.setBranding("foo");
    Locale.setDefault(Locale.JAPAN);
    ifl = new InstalledFileLocatorImpl();
}
 
Example 7
Source File: InstalledFileLocatorImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    scratch = new File(getWorkDir(), "install");
    nbhome = new File(scratch, "nbhome");
    touch(file(nbhome, "a/b"));
    touch(file(nbhome, "a/c"));
    touch(file(nbhome, "d"));
    touch(file(nbhome, "e/f/g"));
    touch(file(nbhome, "loc/x.html"));
    touch(file(nbhome, "loc/x_ja.html"));
    touch(file(nbhome, "loc/x_foo.html"));
    touch(file(nbhome, "loc/x_foo_ja.html"));
    touch(file(nbhome, "loc/y.html"));
    touch(file(nbhome, "h_ja"));
    nbuser = new File(getWorkDir(), "nbuser");
    touch(file(nbuser, "a/b"));
    nbdir1 = new File(scratch, "nbdir1");
    touch(file(nbdir1, "e/f/g"));
    nbdir2 = new File(scratch, "nbdir2");
    touch(file(nbdir2, "h"));
    touch(file(nbdir2, "loc/y_foo.html"));
    File nbdirx = new File(scratch, "nbdirx"); // nonexistent dir
    System.setProperty("netbeans.home", nbhome.getAbsolutePath());
    PlacesTestUtils.setUserDirectory(nbuser);
    System.setProperty("netbeans.dirs",
        nbdir1.getAbsolutePath() + File.pathSeparatorChar +
        nbdir2.getAbsolutePath() + File.pathSeparatorChar +
        // Useless trailing separator intentional:
        nbdirx.getAbsolutePath() + File.pathSeparatorChar);
    NbBundle.setBranding("foo");
    ifl = new InstalledFileLocatorImpl();
}
 
Example 8
Source File: Activator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void start(final BundleContext context) throws Exception {
        if (System.getProperty("netbeans.home") != null) {
            throw new IllegalStateException("Should not be run from inside regular NetBeans module system");
        }
        String storage = context.getProperty(Constants.FRAMEWORK_STORAGE);
        if (storage != null) {
            System.setProperty("netbeans.user", storage);
        }
        System.setProperty("TopSecurityManager.disable", "true");
        NbBundle.setBranding(System.getProperty("branding.token"));
        OSGiMainLookup.initialize(context);
        queue = new DependencyQueue<String,Bundle>();
        this.context = context;
        framework = ((Framework) context.getBundle(0));
        if (framework.getState() == Bundle.STARTING) {
            LOG.fine("framework still starting");
            final AtomicReference<FrameworkListener> frameworkListener = new AtomicReference<FrameworkListener>();
            frameworkListener.set(new FrameworkListener() {
                public @Override void frameworkEvent(FrameworkEvent event) {
                    if (event.getType() == FrameworkEvent.STARTED) {
//                        System.err.println("framework started");
                        context.removeFrameworkListener(frameworkListener.get());
                        context.addBundleListener(Activator.this);
                        processLoadedBundles();
                    }
                }
            });
            context.addFrameworkListener(frameworkListener.get());
        } else {
            LOG.fine("framework already started");
            context.addBundleListener(this);
            processLoadedBundles();
        }
    }
 
Example 9
Source File: AlwaysEnabledActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    NbBundle.setBranding("big");
    folder = FileUtil.getConfigFile("actions/support/test");
    assertNotNull("testing layer is loaded: ", folder);

    myIconResourceCounter = 0;
    myListenerCalled = 0;
    myListenerCounter = 0;
    MyAction.last = null;
}
 
Example 10
Source File: NbBundleTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void testLocalizingSuffixes() throws Exception {
    assertEquals("_en_US,_en,", locSuff());
    Locale.setDefault(Locale.JAPAN);
    assertEquals("_ja_JP,_ja,", locSuff());
    NbBundle.setBranding("f4j_ce");
    Locale.setDefault(Locale.US);
    assertEquals("_f4j_ce_en_US,_f4j_ce_en,_f4j_ce,_f4j_en_US,_f4j_en,_f4j,_en_US,_en,", locSuff());
    Locale.setDefault(Locale.JAPAN);
    assertEquals("_f4j_ce_ja_JP,_f4j_ce_ja,_f4j_ce,_f4j_ja_JP,_f4j_ja,_f4j,_ja_JP,_ja,", locSuff());
}
 
Example 11
Source File: HintTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private HintTest() throws Exception {
    List<URL> layers = new LinkedList<URL>();

    for (String layer : new String[] {"META-INF/generated-layer.xml"}) {
        boolean found = false;

        for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(layer); en.hasMoreElements(); ) {
            found = true;
            layers.add(en.nextElement());
        }

        Assert.assertTrue(layer, found);
    }

    XMLFileSystem xmlFS = new XMLFileSystem();
    xmlFS.setXmlUrls(layers.toArray(new URL[0]));

    FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});

    Repository repository = new Repository(system);

    assertEquals(Lookup.getDefault().getClass().getCanonicalName(), TestLookup.class, Lookup.getDefault().getClass());

    ((TestLookup) Lookup.getDefault()).setLookupsImpl(
        Lookups.fixed(repository,
                      new TestProxyClassPathProvider(),
                      new TestSourceForBinaryQuery(),
                      new TestSourceLevelQueryImplementation(),
                      new TestCompilerOptionsQueryImplementation(),
                      JavaDataLoader.findObject(JavaDataLoader.class, true)),
        Lookups.metaInfServices(HintTest.class.getClassLoader()),
        Lookups.singleton(HintTest.class.getClassLoader())
    );

    Set<String> amt = MimeTypes.getAllMimeTypes();
    if (amt == null) {
        amt = new HashSet<String>();
    } else {
        amt = new HashSet<String>(amt);
    }
    amt.add("text/x-java");
    MimeTypes.setAllMimeTypes(amt);
    org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();

    testPreferences = new TempPreferences();
    hintSettings = new HintsSettings() {
        @Override public boolean isEnabled(HintMetadata hint) {
            return true;
        }
        @Override public void setEnabled(HintMetadata hint, boolean value) {
            throw new UnsupportedOperationException("Not supported.");
        }
        @Override public Preferences getHintPreferences(HintMetadata hint) {
            return testPreferences;
        }
        @Override public Severity getSeverity(HintMetadata hint) {
            return hint.severity;
        }
        @Override public void setSeverity(HintMetadata hint, Severity severity) {
            throw new UnsupportedOperationException("Not supported.");
        }
    };

    workDir = getWorkDir();
    deleteSubFiles(workDir);
    FileUtil.refreshFor(workDir);

    FileObject wd = FileUtil.toFileObject(workDir);
    
    assertNotNull(wd);

    sourceRoot = FileUtil.createFolder(wd, "src");
    buildRoot = FileUtil.createFolder(wd, "build");
    cache = FileUtil.createFolder(wd, "cache");

    CacheFolder.setCacheFolder(cache);

    NbBundle.setBranding("test");

    sourcePath = ClassPathSupport.createClassPath(sourceRoot);
    
    Main.initializeURLFactory();
    JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
}
 
Example 12
Source File: StampsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    NbBundle.setBranding(branding);
    Locale.setDefault(locale);
}
 
Example 13
Source File: NbBundleTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    Locale.setDefault(Locale.US);
    NbBundle.setBranding(null);
    NbBundle.localizedFileCache.clear();
    NbBundle.bundleCache.clear();
}
 
Example 14
Source File: HintTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private HintTestBase(FileObject sourceRoot) throws Exception {
    Set<String> amt = MimeTypes.getAllMimeTypes();
    if (amt == null) {
        amt = new HashSet<String>();
    } else {
        amt = new HashSet<String>(amt);
    }
    amt.add("text/x-java");
    MimeTypes.setAllMimeTypes(amt);
    org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();

    testPreferences = new TempPreferences();
    hintSettings = new HintsSettings() {
        @Override public boolean isEnabled(HintMetadata hint) {
            return true;
        }
        @Override public void setEnabled(HintMetadata hint, boolean value) {
            throw new UnsupportedOperationException("Not supported.");
        }
        @Override public Preferences getHintPreferences(HintMetadata hint) {
            return testPreferences;
        }
        @Override public Severity getSeverity(HintMetadata hint) {
            return hint.severity;
        }
        @Override public void setSeverity(HintMetadata hint, Severity severity) {
            throw new UnsupportedOperationException("Not supported.");
        }
    };

    workDir = getWorkDir();
    FileUtil.refreshFor(workDir);

    FileObject wd = FileUtil.toFileObject(workDir);
    
    assertNotNull(wd);

    this.sourceRoot = sourceRoot;
    buildRoot = FileUtil.createFolder(wd, "build");
    cache = FileUtil.createFolder(wd, "cache");

    CacheFolder.setCacheFolder(cache);

    NbBundle.setBranding("test");

    sourcePath = ClassPathSupport.createClassPath(sourceRoot);
    
    Main.initializeURLFactory();
}