Search in sources :

Example 1 with RepositoryGenerator

use of org.apache.aries.application.management.spi.repository.RepositoryGenerator in project aries by apache.

the class OBRResolverAdvancedTest method testRepoAgain.

@Test
public void testRepoAgain() throws Exception {
    // do not provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    String fileURI = new File(REPO_BUNDLE + ".jar").toURI().toString();
    File repoXml = new File("repository.xml");
    if (repoXml.exists()) {
        repoXml.delete();
    }
    repositoryGenerator.generateRepository(new String[] { fileURI }, new FileOutputStream(repoXml));
    //print out the repository.xml
    BufferedReader reader = new BufferedReader(new FileReader(new File("repository.xml")));
    String line;
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }
    // compare the generated with the expected file
    Document real_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("repository.xml"));
    Document expected_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("/obr/aries.bundle1/expectedRepository.xml"));
    // parse two documents to make sure they have the same number of elements
    Element element_real = real_doc.getDocumentElement();
    Element element_expected = expected_doc.getDocumentElement();
    NodeList nodes_real = element_real.getElementsByTagName("capability");
    NodeList nodes_expected = element_expected.getElementsByTagName("capability");
    assertEquals("The number of capability is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
    nodes_real = element_real.getElementsByTagName("require");
    nodes_expected = element_expected.getElementsByTagName("require");
    assertEquals("The number of require elements is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
    nodes_real = element_real.getElementsByTagName("p");
    nodes_expected = element_expected.getElementsByTagName("p");
    assertEquals("The number of properties is not expected. ", nodes_expected.getLength(), nodes_real.getLength());
    // Let's verify all p elements are shown as expected.
    for (int index = 0; index < nodes_expected.getLength(); index++) {
        Node node = nodes_expected.item(index);
        boolean contains = false;
        // make sure the node exists in the real generated repository
        for (int i = 0; i < nodes_real.getLength(); i++) {
            Node real_node = nodes_real.item(i);
            if (node.isEqualNode(real_node)) {
                contains = true;
                break;
            }
        }
        assertTrue("The node " + node.toString() + "should exist.", contains);
    }
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Document(org.w3c.dom.Document) File(java.io.File) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with RepositoryGenerator

use of org.apache.aries.application.management.spi.repository.RepositoryGenerator in project aries by apache.

the class OBRResolverTest method generateOBRRepoXML.

private void generateOBRRepoXML(String... bundleFiles) throws Exception {
    Set<ModelledResource> mrs = new HashSet<ModelledResource>();
    FileOutputStream fout = new FileOutputStream("repository.xml");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
    for (String fileName : bundleFiles) {
        File bundleFile = new File(fileName);
        IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
        mrs.add(modelledResourceManager.getModelledResource(bundleFile.toURI().toString(), jarDir));
    }
    repositoryGenerator.generateRepository("Test repo description", mrs, fout);
    fout.close();
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ModelledResourceManager(org.apache.aries.application.modelling.ModelledResourceManager) File(java.io.File) HashSet(java.util.HashSet) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 3 with RepositoryGenerator

use of org.apache.aries.application.management.spi.repository.RepositoryGenerator in project aries by apache.

the class AriesRepositoryGenerator method main.

/**
   * Execute this program using 
   * java -jar thisbundlename arg0 arg1...
   * arg0 can be the location of the repository xml or a url
   * arg1... a list of url. If there is a file url, all jar/wars under the url are to be included.
   * e.g. file:///c:/temp/, all jars/wars under temp or its subdirectory are to be included.
   * @param args
   */
public static void main(String[] args) {
    String[] urlArray = args;
    if (args.length == 0) {
        usage();
        System.exit(0);
    } else {
        AriesRepositoryGenerator generator = new AriesRepositoryGenerator();
        // set the system property for logging if not set in the command line
        String loggerLevelProp = "org.ops4j.pax.logging.DefaultServiceLog.level";
        if (System.getProperty(loggerLevelProp) == null) {
            System.setProperty(loggerLevelProp, ERROR_LEVEL);
        }
        FileOutputStream fout = null;
        try {
            BundleContext ctx = generator.startFramework();
            // get the object of repositoryGenerator and call its method
            File xmlFile = new File(DEFAULT_REPO_NAME);
            if (args[0].endsWith(".xml")) {
                xmlFile = new File(args[0]);
                // get the directors
                File parentDir = xmlFile.getAbsoluteFile().getParentFile();
                if (!!!parentDir.exists()) {
                    parentDir.mkdirs();
                }
                // put the rest of the args to the list of urls
                if (args.length > 1) {
                    urlArray = Arrays.copyOfRange(args, 1, args.length);
                } else {
                    usage();
                    System.exit(0);
                }
            }
            // Use reflection to get around the class loading issue
            fout = new FileOutputStream(xmlFile);
            Object repoGen = generator.getOsgiService(ctx, RepositoryGenerator.class.getName());
            Class gen = repoGen.getClass();
            Method m = gen.getDeclaredMethod("generateRepository", new Class[] { String[].class, OutputStream.class });
            m.invoke(repoGen, urlArray, fout);
            generator.stopFramework();
            System.out.println("The reporsitory xml was generated successfully under " + xmlFile.getAbsolutePath() + ".");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        } finally {
            try {
                if (fout != null)
                    fout.close();
            } catch (IOException e) {
                fout = null;
            }
        }
    }
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) Method(java.lang.reflect.Method) IOException(java.io.IOException) File(java.io.File) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext)

Example 4 with RepositoryGenerator

use of org.apache.aries.application.management.spi.repository.RepositoryGenerator in project aries by apache.

the class OBRResolverAdvancedTest method generateOBRRepoXML.

private void generateOBRRepoXML(boolean nullURI, String... bundleFiles) throws Exception {
    Set<ModelledResource> mrs = new HashSet<ModelledResource>();
    FileOutputStream fout = new FileOutputStream("repository.xml");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
    for (String fileName : bundleFiles) {
        File bundleFile = new File(fileName);
        IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
        String uri = "";
        if (!!!nullURI) {
            uri = bundleFile.toURI().toString();
        }
        if ("delete.jar".equals(fileName)) {
            jarDir = null;
        }
        mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
    }
    repositoryGenerator.generateRepository("Test repo description", mrs, fout);
    fout.close();
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ModelledResourceManager(org.apache.aries.application.modelling.ModelledResourceManager) File(java.io.File) HashSet(java.util.HashSet) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 RepositoryGenerator (org.apache.aries.application.management.spi.repository.RepositoryGenerator)4 HashSet (java.util.HashSet)2 ModelledResource (org.apache.aries.application.modelling.ModelledResource)2 ModelledResourceManager (org.apache.aries.application.modelling.ModelledResourceManager)2 IDirectory (org.apache.aries.util.filesystem.IDirectory)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1 BundleException (org.osgi.framework.BundleException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1