Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:org.apache.hadoop.gateway.topology.xml.TopologyRulesModuleTest.java

@Test
public void testParseSimpleTopologyXmlInHadoopFormat() throws IOException, SAXException, URISyntaxException {
    Digester digester = loader.newDigester();
    String name = "org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.conf";
    URL url = ClassLoader.getSystemResource(name);
    assertThat("Failed to find URL for resource " + name, url, notNullValue());
    File file = new File(url.getFile());
    TopologyBuilder topologyBuilder = digester.parse(url);
    Topology topology = topologyBuilder.build();
    assertThat("Failed to parse resource " + name, topology, notNullValue());
    topology.setTimestamp(file.lastModified());

    assertThat(topology.getName(), is("topology2"));
    assertThat(topology.getTimestamp(), is(file.lastModified()));
    assertThat(topology.getServices().size(), is(4));
    assertThat(topology.getProviders().size(), is(2));

    Service webhdfsService = topology.getService("WEBHDFS", null);
    assertThat(webhdfsService, notNullValue());
    assertThat(webhdfsService.getRole(), is("WEBHDFS"));
    assertThat(webhdfsService.getName(), nullValue());
    assertThat(webhdfsService.getUrl(), is("http://host:50070/webhdfs"));

    Service webhcatService = topology.getService("WEBHCAT", null);
    assertThat(webhcatService, notNullValue());
    assertThat(webhcatService.getRole(), is("WEBHCAT"));
    assertThat(webhcatService.getName(), nullValue());
    assertThat(webhcatService.getUrl(), is("http://host:50111/templeton"));

    Service oozieService = topology.getService("OOZIE", null);
    assertThat(oozieService, notNullValue());
    assertThat(oozieService.getRole(), is("OOZIE"));
    assertThat(oozieService.getName(), nullValue());
    assertThat(oozieService.getUrl(), is("http://host:11000/oozie"));

    Service hiveService = topology.getService("HIVE", null);
    assertThat(hiveService, notNullValue());
    assertThat(hiveService.getRole(), is("HIVE"));
    assertThat(hiveService.getName(), nullValue());
    assertThat(hiveService.getUrl(), is("http://host:10000"));

    Provider authenticationProvider = topology.getProvider("authentication", "ShiroProvider");
    assertThat(authenticationProvider, notNullValue());
    assertThat(authenticationProvider.isEnabled(), is(true));
    assertThat(authenticationProvider.getRole(), is("authentication"));
    assertThat(authenticationProvider.getName(), is("ShiroProvider"));
    assertThat(authenticationProvider.getParams().size(), is(5));
    assertThat(authenticationProvider.getParams().get("main.ldapRealm.contextFactory.url"),
            is("ldap://localhost:33389"));

    Provider identityAssertionProvider = topology.getProvider("identity-assertion", "Pseudo");
    assertThat(identityAssertionProvider, notNullValue());
    assertThat(identityAssertionProvider.isEnabled(), is(false));
    assertThat(identityAssertionProvider.getRole(), is("identity-assertion"));
    assertThat(identityAssertionProvider.getName(), is("Pseudo"));
    assertThat(identityAssertionProvider.getParams().size(), is(2));
    assertThat(identityAssertionProvider.getParams().get("name"), is("user.name"));
}

From source file:fr.gael.dhus.server.http.TomcatServer.java

/**
 * Initialize Tomcat inner datasets./*from w  w  w  .ja  v a  2s  .com*/
 */
public void init() throws TomcatException {
    tomcatpath = configurationManager.getTomcatConfiguration().getPath();
    final String extractDirectory = tomcatpath;

    File extractDirectoryFile = new File(extractDirectory);
    logger.info("Starting tomcat in " + extractDirectoryFile.getPath());

    try {
        extract(extractDirectoryFile, extractDirectory);
        // create tomcat various paths
        new File(extractDirectory, "conf").mkdirs();
        File cfg = new File(ClassLoader.getSystemResource("server.xml").toURI());
        Files.copy(cfg, new File(extractDirectory, "conf/server.xml"));
        new File(extractDirectory, "logs").mkdirs();
        new File(extractDirectory, "webapps").mkdirs();
        new File(extractDirectory, "work").mkdirs();
        File tmpDir = new File(extractDirectory, "temp");
        tmpDir.mkdirs();

        System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
        System.setProperty("catalina.base", extractDirectoryFile.getAbsolutePath());
        System.setProperty("catalina.home", extractDirectoryFile.getAbsolutePath());

        cat = new Catalina();
    } catch (Exception e) {
        throw new TomcatException("Cannot initalize Tomcat environment.", e);
    }

    Runtime.getRuntime().addShutdownHook(new TomcatShutdownHook());
}

From source file:org.openxdata.test.BaseContextSensitiveTest.java

private static URL getInitalDatasetURL() throws FileNotFoundException {
    URL file = ClassLoader.getSystemResource(INITIAL_XML_DATASET_LOCATION);
    if (file == null) {
        throw new FileNotFoundException(
                "Unable to find '" + INITIAL_XML_DATASET_LOCATION + "' in the classpath");
    }/*w  ww  .  j a  va 2s .c o  m*/
    return file;
}

From source file:algo.PlotBar.java

/**
 * Creates new form Algorithm/*w  ww . j a  v a 2s.c  o m*/
 *
 * @throws java.io.IOException
 */
public Algorithm() throws IOException {
    setTitle("Algorithm Simulation");
    initComponents();
    BufferedImage wPic = ImageIO.read(ClassLoader.getSystemResource("algo/res/bubbles.jpg"));
    imageLabel.setIcon(new ImageIcon(wPic));
}

From source file:org.walkmod.conf.providers.IvyConfigurationProvider.java

/**
 * Ivy configuration initialization/*from w  ww  .j a  v  a 2 s.  com*/
 *
 * @throws ParseException
 *             If an error occurs when loading ivy settings file
 *             (ivysettings.xml)
 * @throws IOException
 *             If an error occurs when reading ivy settings file
 *             (ivysettings.xml)
 * @throws ConfigurationException
 *             If ivy settings file (ivysettings.xml) is not found in
 *             classpath
 */
public void initIvy() throws ParseException, IOException, ConfigurationException {
    // creates clear ivy settings
    IvySettings ivySettings = new IvySettings();
    File settingsFile = new File(IVY_SETTINGS_FILE);
    if (settingsFile.exists()) {
        ivySettings.load(settingsFile);
    } else {
        URL settingsURL = ClassLoader.getSystemResource(IVY_SETTINGS_FILE);
        if (settingsURL == null) {
            // file not found in System classloader, we try the current one
            settingsURL = this.getClass().getClassLoader().getResource(IVY_SETTINGS_FILE);
            // extra validation to avoid uncontrolled NullPointerException
            // when invoking toURI()
            if (settingsURL == null)
                throw new ConfigurationException(
                        "Ivy settings file (" + IVY_SETTINGS_FILE + ") could not be found in classpath");
        }
        ivySettings.load(settingsURL);
    }
    // creates an Ivy instance with settings
    ivy = Ivy.newInstance(ivySettings);

    ivyfile = File.createTempFile("ivy", ".xml");
    ivyfile.deleteOnExit();

    String[] confs = new String[] { "default" };
    resolveOptions = new ResolveOptions().setConfs(confs);
    if (isOffLine) {
        resolveOptions = resolveOptions.setUseCacheOnly(true);
    } else {
        Map<String, Object> params = configuration.getParameters();
        if (params != null) {
            Object value = params.get("offline");
            if (value != null) {
                String offlineOpt = value.toString();
                if (offlineOpt != null) {
                    boolean offline = Boolean.parseBoolean(offlineOpt);
                    if (offline) {
                        resolveOptions = resolveOptions.setUseCacheOnly(true);
                    }
                }
            }
        }
    }
}

From source file:org.jboss.pressgang.ccms.contentspec.client.commands.CheckoutCommandTest.java

@Before
public void setUp() throws IOException {
    bindStdOut();/*from w w w  . j a va2s . c  o m*/
    PowerMockito.mockStatic(RESTProviderFactory.class);
    when(RESTProviderFactory.create(anyString())).thenReturn(providerFactory);
    when(providerFactory.getProvider(ContentSpecProvider.class)).thenReturn(contentSpecProvider);
    command = new CheckoutCommand(parser, cspConfig, clientConfig);

    // Return the test directory as the root directory
    rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource(""));
    when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator);

    // Make the book title directory
    bookDir = new File(rootTestDirectory, BOOK_TITLE);
    bookDir.mkdir();

    // Make a empty file in that directory
    emptyFile = new File(bookDir, EMPTY_FILE_NAME);
    emptyFile.createNewFile();
}

From source file:org.apache.tajo.engine.eval.ExprTestBase.java

@BeforeClass
public static void setUp() throws Exception {
    cluster = new TajoTestingCluster();
    conf = cluster.getConfiguration();/*from   www .jav  a2  s  . c  o m*/
    cluster.startCatalogCluster();
    cat = cluster.getCatalogService();
    cat.createTablespace(DEFAULT_TABLESPACE_NAME, "hdfs://localhost:1234/warehouse");
    cat.createDatabase(DEFAULT_DATABASE_NAME, DEFAULT_TABLESPACE_NAME);
    Map<FunctionSignature, FunctionDesc> map = FunctionLoader.loadBuiltinFunctions();
    List<FunctionDesc> list = new ArrayList<>(map.values());
    list.addAll(FunctionLoader.loadUserDefinedFunctions(conf).orElse(new ArrayList<>()));

    // load Hive UDFs
    URL hiveUDFURL = ClassLoader.getSystemResource("hiveudf");
    Preconditions.checkNotNull(hiveUDFURL, "hive udf directory is absent.");
    conf.set(TajoConf.ConfVars.HIVE_UDF_JAR_DIR.varname, hiveUDFURL.toString().substring("file:".length()));
    list.addAll(HiveFunctionLoader.loadHiveUDFs(conf).orElse(new ArrayList<>()));

    for (FunctionDesc funcDesc : list) {
        cat.createFunction(funcDesc);
    }

    analyzer = new SQLAnalyzer();
    preLogicalPlanVerifier = new PreLogicalPlanVerifier(cat);
    planner = new LogicalPlanner(cat, TablespaceManager.getInstance());
    optimizer = new LogicalOptimizer(cluster.getConfiguration(), cat, TablespaceManager.getInstance());
    annotatedPlanVerifier = new LogicalPlanVerifier();
}

From source file:com.depas.utils.FileUtils.java

/**
 * Gets the root directory that we will initialize the GEN3 license framework.
 * @param c the c/* w w  w  .  jav  a 2 s  .c  o m*/
 * @return the license root path
 */
public static String getLicensingRootPath(Class<?> c) {
    try {
        // get url to iwc directory on classpath
        URL url = ClassLoader.getSystemResource("iwc");
        if (url != null) {
            File iwcDir = new File(url.toURI());
            // go up one to ignite_config
            // go up one more then to root
            File baseDir = iwcDir.getParentFile().getParentFile();

            String path = baseDir.getPath();
            if (path.endsWith("\\") == false && path.endsWith("/") == false) {
                path += "/";
            }
            // licensing, should be at same level as ignite_config
            path += "licensing/";
            return URLDecoder.decode(path, "UTF-8");
        } else {
            return null;
        }
    } catch (Exception ex) {
        logger.warn("Error obtaining file path to license directory: " + ex);
        return null;
    }
}

From source file:dk.dma.ais.encode.EncodeTest.java

@Test
public void aisDecodeEncode() throws IOException, SentenceException, SixbitException, AisMessageException {

    URL url = ClassLoader.getSystemResource("decode_encode_messages.txt");
    Assert.assertNotNull(url);//from   w w  w  .j a  v a  2s.  c om
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    Assert.assertNotNull(in);
    String line;
    Vdm vdm = new Vdm();
    while ((line = in.readLine()) != null) {
        try {
            int res = vdm.parse(line);
            if (res != 0) {
                continue;
            }

            AisMessage msg = AisMessage.getInstance(vdm);
            Assert.assertNotNull(msg);

            if (!(msg instanceof AisPositionMessage) || !(msg instanceof AisMessage4)
                    || !(msg instanceof AisStaticCommon)) {
                vdm = new Vdm();
                continue;
            }

            String expected = vdm.getSixbitString();
            String encoded = msg.getEncoded().encode();
            Assert.assertTrue(expected.equals(encoded));

            vdm = new Vdm();

        } catch (SixbitException e) {
            System.err.println("Failed line: " + line);
            throw e;
        }
    }
}

From source file:org.n52.sir.IT.DescribeSensorIT.java

@Test
public void describeSensorWithTestFile() throws Exception {
    DescribeSensorRequestDocument doc = DescribeSensorRequestDocument.Factory
            .parse(new File(ClassLoader.getSystemResource("Requests/sir/DescribeSensor.xml").getFile()));
    doc.getDescribeSensorRequest().setSensorIDInSIR(sensorID);

    XmlObject response = client.xSendPostRequest(doc);
    SensorMLDocument actual = SensorMLDocument.Factory.parse(response.getDomNode());
    checkSensor(actual);/*from ww  w  . j a  v a2  s. co m*/
}