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);
}
}
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();
}
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;
}
}
}
}
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();
}
Aggregations