Search in sources :

Example 31 with Bundle

use of org.osgi.framework.Bundle in project tesb-studio-se by Talend.

the class FelixLogsModelTest method testToString.

/**
     * Test method for {@link org.talend.designer.esb.runcontainer.logs.FelixLogsModel#toString()}.
     * 
     * @throws Exception
     */
@Test
public void testToString() throws Exception {
    Bundle b = Platform.getBundle("org.talend.designer.esb.runcontainer.test");
    //$NON-NLS-1$
    URL url = FileLocator.toFileURL(FileLocator.find(b, new Path("resources"), null));
    //$NON-NLS-1$
    File responseFile = new File(url.getPath() + "/FelixLogsModelTest.json");
    Assert.assertTrue(responseFile.exists());
    String json = new String(Files.readAllBytes(responseFile.toPath()));
    String data = "\"data\":";
    int dataPos = json.indexOf(data) + 7;
    String line = json.substring(dataPos, json.length());
    ObjectMapper mapper = new ObjectMapper();
    FelixLogsModel[] logs = mapper.readValue(line, FelixLogsModel[].class);
    Assert.assertEquals(logs.length, 100);
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) File(java.io.File) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 32 with Bundle

use of org.osgi.framework.Bundle in project tesb-studio-se by Talend.

the class FileUtilTest method testIsContainerArchive.

/**
     * Test method for {@link org.talend.designer.esb.runcontainer.util.FileUtil#isContainerArchive(java.lang.String)}.
     * 
     * @throws Exception
     */
@Test
public void testIsContainerArchive() throws Exception {
    Bundle b = Platform.getBundle("org.talend.designer.esb.runcontainer.test");
    //$NON-NLS-1$
    URL url = FileLocator.toFileURL(FileLocator.find(b, new Path("resources"), null));
    Assert.assertTrue(FileUtil.isContainerArchive(url.getPath() + "/Talend-ESB-V6.4.0-structure.zip"));
    Assert.assertTrue(FileUtil.isContainerArchive(url.getPath() + "/Talend-Runtime-V6.4.0-structure.zip"));
    Assert.assertFalse(FileUtil.isContainerArchive(url.getPath() + "/Talend-ESB-V6.4.0-missing-trun.zip"));
    Assert.assertFalse(FileUtil.isContainerArchive(url.getPath() + "/Talend-Runtime-V6.4.0-structure-missing-etc.zip"));
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) URL(java.net.URL) Test(org.junit.Test)

Example 33 with Bundle

use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.

the class JobJavaScriptsWSManager method copyServerConfigFileToTempDir.

private void copyServerConfigFileToTempDir() {
    final Bundle b = Platform.getBundle(RepositoryPlugin.PLUGIN_ID);
    String sourceFileName;
    try {
        sourceFileName = //$NON-NLS-1$
        FileLocator.toFileURL(FileLocator.find(b, new Path("resources/server-config.wsdd"), null)).getFile();
        //$NON-NLS-1$
        String targetFileName = getTmpFolder() + PATH_SEPARATOR + "server-config.wsdd";
        FilesUtils.copyFile(new File(sourceFileName), new File(targetFileName));
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) File(java.io.File)

Example 34 with Bundle

use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.

the class TestComponentsAction method getPath.

private String getPath() {
    //$NON-NLS-1$
    IPath filePath = new Path("components");
    Bundle b = Platform.getBundle(TestComponentsPlugin.PLUGINCOMPONENTID);
    String dir = null;
    try {
        URL url = FileLocator.toFileURL(FileLocator.find(b, filePath, null));
        dir = url.getPath();
        dir = dir.substring(1, dir.length() - 1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return dir;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) URL(java.net.URL)

Example 35 with Bundle

use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.

the class URLUtil method getFragmentResourceURL.

/**
     * Return a URL to a file located in your plugin fragment.
     * 
     * @param yourPluginId e.g net.sourceforge.sqlexplorer.oracle
     * @param filePath path to file within your fragment e.g. icons/test.gif
     * @return URL to the file.
     */
public static URL getFragmentResourceURL(String yourPluginId, String filePath) {
    URL url = null;
    try {
        Bundle bundle = Platform.getBundle(yourPluginId);
        //$NON-NLS-1$
        URL baseUrl = bundle.getEntry("/");
        url = new URL(baseUrl, filePath);
    } catch (Exception e) {
        SqlBuilderPlugin.log(e.getMessage(), e);
    }
    return url;
}
Also used : Bundle(org.osgi.framework.Bundle) URL(java.net.URL)

Aggregations

Bundle (org.osgi.framework.Bundle)2527 Test (org.junit.Test)674 URL (java.net.URL)389 BundleContext (org.osgi.framework.BundleContext)319 ArrayList (java.util.ArrayList)299 File (java.io.File)298 IOException (java.io.IOException)281 BundleException (org.osgi.framework.BundleException)273 HashMap (java.util.HashMap)155 ServiceReference (org.osgi.framework.ServiceReference)152 Hashtable (java.util.Hashtable)131 Path (org.eclipse.core.runtime.Path)126 HashSet (java.util.HashSet)98 InputStream (java.io.InputStream)94 List (java.util.List)87 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73