Return-Path: X-Original-To: apmail-ace-commits-archive@www.apache.org Delivered-To: apmail-ace-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7DA4918AAE for ; Thu, 11 Feb 2016 11:33:58 +0000 (UTC) Received: (qmail 35520 invoked by uid 500); 11 Feb 2016 11:33:58 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 35492 invoked by uid 500); 11 Feb 2016 11:33:58 -0000 Mailing-List: contact commits-help@ace.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ace.apache.org Delivered-To: mailing list commits@ace.apache.org Received: (qmail 35481 invoked by uid 99); 11 Feb 2016 11:33:58 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Feb 2016 11:33:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id D60DC180059 for ; Thu, 11 Feb 2016 11:33:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.471 X-Spam-Level: * X-Spam-Status: No, score=1.471 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id nAO4_PKO57sV for ; Thu, 11 Feb 2016 11:33:48 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 45BCD20271 for ; Thu, 11 Feb 2016 11:33:48 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id C3F04E0099 for ; Thu, 11 Feb 2016 11:33:47 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B54E13A023C for ; Thu, 11 Feb 2016 11:33:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1729811 - in /ace/trunk: org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ org.apache.ace.bnd/ org.apache.ace.bnd/src/org/apache/ace/bnd/registry/ org.apache.ace.client.automation/ org.apache.ace.client.repository.i... Date: Thu, 11 Feb 2016 11:33:47 -0000 To: commits@ace.apache.org From: jawi@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160211113347.B54E13A023C@svn01-us-west.apache.org> Author: jawi Date: Thu Feb 11 11:33:46 2016 New Revision: 1729811 URL: http://svn.apache.org/viewvc?rev=1729811&view=rev Log: ACE-314 - Upgrade OBR implementation to generate R5 repositories: - applied patch from @brampouwelse; - this closes #4 from GitHub. Added: ace/trunk/org.apache.ace.bnd/registry.bnd ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java (with props) ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/packageinfo ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java (with props) ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java (with props) ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java (with props) Removed: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/bindex/ ace/trunk/org.apache.ace.obr/src/org/osgi/ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/bindeximpl/ Modified: ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java ace/trunk/org.apache.ace.client.automation/bnd.bnd ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java ace/trunk/org.apache.ace.client.repository/api.bnd ace/trunk/org.apache.ace.deployment/servlet.bnd ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/AgentDeploymentServlet.java ace/trunk/org.apache.ace.gogo/bnd.bnd ace/trunk/org.apache.ace.obr/bnd.bnd ace/trunk/org.apache.ace.obr/metadata.bnd ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/MetadataGenerator.java ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java ace/trunk/org.apache.ace.obr/storage.bnd ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java ace/trunk/org.apache.ace.webui.vaadin/bnd.bnd ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/OBRUtil.java ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java ace/trunk/run-client/conf/org.apache.ace.webui.vaadin.cfg ace/trunk/run-server-allinone/conf/org.apache.ace.webui.vaadin.cfg ace/trunk/run-server-allinone/scripts/clear.gogo Modified: ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java (original) +++ ace/trunk/org.apache.ace.authentication.itest/src/org/apache/ace/it/authentication/ObrAuthenticationTest.java Thu Feb 11 11:33:46 2016 @@ -128,7 +128,7 @@ public class ObrAuthenticationTest exten importSingleUser(m_userRepository, userName, password); waitForUser(m_userAdmin, userName); - URL testURL = new URL(m_obrURL, "repository.xml"); + URL testURL = new URL(m_obrURL, "index.xml"); assertTrue("Failed to access OBR in time!", waitForURL(m_connectionFactory, testURL, 401, 15000)); @@ -158,11 +158,11 @@ public class ObrAuthenticationTest exten } /** - * Test that we can retrieve the 'repository.xml' from the OBR. + * Test that we can retrieve the 'index.xml' from the OBR. */ public void testAccessObrRepositoryWithCredentialsOk() throws Exception { try { - URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml"); + URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/index.xml"); URLConnection conn = m_connectionFactory.createConnection(url); assertNotNull(conn); Object content = conn.getContent(); @@ -175,11 +175,11 @@ public class ObrAuthenticationTest exten } /** - * Test that we cannot retrieve the 'repository.xml' from the OBR without any credentials. + * Test that we cannot retrieve the 'index.xml' from the OBR without any credentials. */ public void testAccessObrRepositoryWithoutCredentialsFail() throws Exception { try { - URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml"); + URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/index.xml"); // do NOT use connection factory as it will supply the credentials for us... URLConnection conn = url.openConnection(); @@ -204,7 +204,7 @@ public class ObrAuthenticationTest exten } /** - * Test that we cannot retrieve the 'repository.xml' from the OBR with incorrect credentials. + * Test that we cannot retrieve the 'index.xml' from the OBR with incorrect credentials. */ public void testAccessObrRepositoryWithWrongCredentialsFail() throws Exception { try { @@ -216,7 +216,7 @@ public class ObrAuthenticationTest exten configuration.update(); - URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/repository.xml"); + URL url = new URL("http://localhost:" + TestConstants.PORT + m_endpoint + "/index.xml"); // do NOT use connection factory as it will supply the credentials for us... URLConnection conn = url.openConnection(); Added: ace/trunk/org.apache.ace.bnd/registry.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/registry.bnd?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.bnd/registry.bnd (added) +++ ace/trunk/org.apache.ace.bnd/registry.bnd Thu Feb 11 11:33:46 2016 @@ -0,0 +1,2 @@ +Bundle-Version: 1.0.0 +Export-Package: org.apache.ace.bnd.registry \ No newline at end of file Added: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java (added) +++ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java Thu Feb 11 11:33:46 2016 @@ -0,0 +1,58 @@ +package org.apache.ace.bnd.registry; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import aQute.bnd.service.Registry; + +/** + * BND Registry implementation that can be used when using bnd plugins + * outside a bnd workspace. + * + */ +public class RegistryImpl implements Registry { + + private final List m_plugins; + + public RegistryImpl() { + m_plugins = new ArrayList<>(); + } + + public RegistryImpl(Object... plugins) { + m_plugins = new ArrayList<>(Arrays.asList(plugins)); + } + + public void addPlugin(Object plugin) { + m_plugins.add(plugin); + } + + public void removePlugin(Object plugin) { + m_plugins.remove(plugin); + } + + @SuppressWarnings("unchecked") + @Override + public List getPlugins(Class c) { + + List plugins = new ArrayList<>(); + for (Object plugin: m_plugins) { + if (c.isInstance(plugin)){ + plugins.add((T)plugin); + } + } + return plugins; + } + + @SuppressWarnings("unchecked") + @Override + public T getPlugin(Class c) { + for (Object plugin: m_plugins) { + if (c.isInstance(plugin)){ + return (T)plugin; + } + } + return null; + } + +} Propchange: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/RegistryImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/packageinfo URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/packageinfo?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/packageinfo (added) +++ ace/trunk/org.apache.ace.bnd/src/org/apache/ace/bnd/registry/packageinfo Thu Feb 11 11:33:46 2016 @@ -0,0 +1 @@ +version 1.0.0 \ No newline at end of file Modified: ace/trunk/org.apache.ace.client.automation/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.automation/bnd.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.client.automation/bnd.bnd (original) +++ ace/trunk/org.apache.ace.client.automation/bnd.bnd Thu Feb 11 11:33:46 2016 @@ -11,6 +11,6 @@ Private-Package: org.apache.ace.client.automation Bundle-Activator: org.apache.ace.client.automation.Activator -Bundle-Version: 1.0.2 +Bundle-Version: 1.0.3 Bundle-Name: Apache ACE Client Automation Bundle-Description: Provides automation tasks for the Apache ACE client \ No newline at end of file Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java (original) +++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java Thu Feb 11 11:33:46 2016 @@ -139,7 +139,7 @@ public abstract class BaseRepositoryAdmi configure("org.apache.ace.obr.storage.file", "OBRInstance", "singleOBRStore", OBRFileStoreConstants.FILE_LOCATION_KEY, fileLocation); // Wait for the endpoint to respond. - URL repoURL = new URL(baseURL + "repository.xml"); + URL repoURL = new URL(baseURL + "index.xml"); int response = ((HttpURLConnection) repoURL.openConnection()).getResponseCode(); int tries = 0; while ((response != 200) && (tries++ < 50)) { @@ -313,7 +313,7 @@ public abstract class BaseRepositoryAdmi configServlet.update(propsServlet); - URL url = new URL("http://localhost:" + TestConstants.PORT + "/" + endpoint + "/repository.xml"); + URL url = new URL("http://localhost:" + TestConstants.PORT + "/" + endpoint + "/index.xml"); int response = ((HttpURLConnection) url.openConnection()).getResponseCode(); int tries = 0; while ((response != 404) && (tries < 50)) { Modified: ace/trunk/org.apache.ace.client.repository/api.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/api.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.client.repository/api.bnd (original) +++ ace/trunk/org.apache.ace.client.repository/api.bnd Thu Feb 11 11:33:46 2016 @@ -6,6 +6,6 @@ Export-Package: org.apache.ace.client.re org.apache.ace.client.repository.object,\ org.apache.ace.client.repository.repository,\ org.apache.ace.client.repository.stateful -Bundle-Version: 2.0.1 +Bundle-Version: 2.0.2 Bundle-Name: Apache ACE Client Repository API Bundle-Description: Provides the Apache ACE Cleint Repository API \ No newline at end of file Modified: ace/trunk/org.apache.ace.deployment/servlet.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/servlet.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.deployment/servlet.bnd (original) +++ ace/trunk/org.apache.ace.deployment/servlet.bnd Thu Feb 11 11:33:46 2016 @@ -3,6 +3,6 @@ Private-Package: org.apache.ace.deployment.servlet Bundle-Activator: org.apache.ace.deployment.servlet.Activator Export-Package: org.apache.ace.deployment.processor -Bundle-Version: 1.0.2 +Bundle-Version: 1.0.3 Bundle-Name: Apache ACE Deployment Servlet Bundle-Description: Registers the Deployment Servlet \ No newline at end of file Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/AgentDeploymentServlet.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/AgentDeploymentServlet.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/AgentDeploymentServlet.java (original) +++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/AgentDeploymentServlet.java Thu Feb 11 11:33:46 2016 @@ -78,7 +78,7 @@ public class AgentDeploymentServlet exte private boolean m_useAuth = false; private URL m_obrURL; - private final String m_repositoryXML = "repository.xml"; + private final String m_repositoryXML = "index.xml"; /** * Gets the actual text from a named item contained in the given node map. @@ -214,7 +214,7 @@ public class AgentDeploymentServlet exte return new URL(m_obrURL, m_repositoryXML); } catch (MalformedURLException e) { - m_log.log(LogService.LOG_ERROR, "Error retrieving repository.xml from " + m_obrURL); + m_log.log(LogService.LOG_ERROR, "Error retrieving index.xml from " + m_obrURL); throw e; } } @@ -247,7 +247,7 @@ public class AgentDeploymentServlet exte NodeList resources; try { URLConnection connection = openConnection(createOBRURL()); - // We always want the newest repository.xml file. + // We always want the newest index.xml file. connection.setUseCaches(false); input = connection.getInputStream(); Modified: ace/trunk/org.apache.ace.gogo/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/bnd.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.gogo/bnd.bnd (original) +++ ace/trunk/org.apache.ace.gogo/bnd.bnd Thu Feb 11 11:33:46 2016 @@ -4,8 +4,8 @@ ${^-buildpath},\ osgi.core;version=6.0.0,\ biz.aQute.repository;version=2.1.0,\ - biz.aQute.bnd;version=2.1.0,\ - org.osgi.impl.bundle.repoindex.lib,\ + biz.aQute.bnd;version=2.1.0;packages="org.osgi.service.indexer,org.osgi.service.indexer.impl,*",\ + org.osgi.impl.bundle.repoindex.lib;packages="org.osgi.service.indexer,org.osgi.service.indexer.impl",\ org.apache.felix.dependencymanager,\ org.apache.felix.gogo.runtime,\ org.apache.ace.bnd.repository;version=latest,\ Modified: ace/trunk/org.apache.ace.obr/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/bnd.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/bnd.bnd (original) +++ ace/trunk/org.apache.ace.obr/bnd.bnd Thu Feb 11 11:33:46 2016 @@ -12,7 +12,7 @@ org.apache.ace.test;version=latest,\ org.apache.ace.deployment.provider.api;version=latest,\ org.apache.ace.deployment.provider.base;version=latest,\ - kxml2;version=2.3.0,\ - org.apache.ace.deployment.util.test;version=latest + org.apache.ace.deployment.util.test;version=latest,\ + org.osgi.impl.bundle.repoindex.lib;packages="org.osgi.service.indexer,org.osgi.service.indexer.impl" Modified: ace/trunk/org.apache.ace.obr/metadata.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/metadata.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/metadata.bnd (original) +++ ace/trunk/org.apache.ace.obr/metadata.bnd Thu Feb 11 11:33:46 2016 @@ -1,20 +1,17 @@ # Licensed to the Apache Software Foundation (ASF) under the terms of ASLv2 (http://www.apache.org/licenses/LICENSE-2.0). -Private-Package: org.apache.ace.obr.metadata.bindex,\ - org.kxml2.io,\ - org.kxml2.kdom,\ - org.kxml2.wap,\ - org.kxml2.wap.syncml,\ - org.kxml2.wap.wml,\ - org.kxml2.wap.wv,\ - org.xmlpull.v1,\ - org.osgi.impl.bundle.bindex,\ - org.osgi.impl.bundle.obr.resource,\ - org.apache.ace.obr.metadata.util -Bundle-Activator: org.apache.ace.obr.metadata.bindex.Activator +Private-Package: \ + org.apache.ace.obr.metadata.repoindex,\ + org.apache.ace.obr.metadata.util,\ + org.osgi.service.indexer,\ + org.osgi.service.indexer.impl,\ + org.osgi.service.indexer.impl.types,\ + org.osgi.service.indexer.impl.util + +Bundle-Activator: org.apache.ace.obr.metadata.repoindex.Activator Export-Package: org.apache.ace.obr.metadata,\ org.osgi.impl.bundle.obr.resource,\ org.osgi.service.obr -Bundle-Version: 2.0.0 +Bundle-Version: 2.0.1 Bundle-Name: Apache ACE OBR MetaData Bundle-Description: Provides the ACE OBR MetaData packages \ No newline at end of file Modified: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/MetadataGenerator.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/MetadataGenerator.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/MetadataGenerator.java (original) +++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/MetadataGenerator.java Thu Feb 11 11:33:46 2016 @@ -28,11 +28,11 @@ public interface MetadataGenerator { /** - * Generates the repository.xml based upon the new set of Bundles in the given directory. The xml is created - * as result of this method in the given directory in a file called repository.xml. + * Generates the index.xml based upon the new set of Bundles in the given directory. The xml is created + * as result of this method in the given directory in a file called index.xml. * This methods creates the file in an atomic fashion (this includes retrying to overwrite an existing file until success). * - * @param directory the location where to store the newly created repository.xml + * @param directory the location where to store the newly created index.xml * * @throws java.io.IOException If I/O problems occur when generating the new meta data index file. */ Added: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java (added) +++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java Thu Feb 11 11:33:46 2016 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ace.obr.metadata.repoindex; + +import org.apache.ace.obr.metadata.MetadataGenerator; +import org.apache.felix.dm.DependencyActivatorBase; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public class Activator extends DependencyActivatorBase { + + @Override + public void init(BundleContext context, DependencyManager manager) throws Exception { + manager.add(createComponent() + .setInterface(MetadataGenerator.class.getName(), null) + .setImplementation(RepoIndexMetadataGenerator.class) + .add(createServiceDependency() + .setService(LogService.class) + .setRequired(false))); + } + + @Override + public void destroy(BundleContext context, DependencyManager manager) throws Exception { + // Nothing to be done + } +} \ No newline at end of file Propchange: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/Activator.java ------------------------------------------------------------------------------ svn:eol-style = native Added: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java (added) +++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java Thu Feb 11 11:33:46 2016 @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ace.obr.metadata.repoindex; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.ace.obr.metadata.MetadataGenerator; +import org.osgi.service.indexer.impl.RepoIndex; +import org.osgi.service.log.LogService; + +public class RepoIndexMetadataGenerator implements MetadataGenerator { + + private static final String INDEX_FILENAME = "index"; + private static final String INDEX_EXTENSION = ".xml"; + + private volatile LogService m_log; /* will be injected by dependencymanager */ + + public void generateMetadata(File directory) throws IOException { + if (directory.isDirectory()) { + final File index = new File(directory, INDEX_FILENAME + INDEX_EXTENSION); + final File tempIndex = File.createTempFile("repo", INDEX_EXTENSION, directory); + + try { + RepoIndex repoIndex = new RepoIndex(m_log); + try (FileOutputStream out = new FileOutputStream(tempIndex)) { + final Set files = new HashSet<>(); + Map config = new HashMap<>(); + Files.walkFileTree(directory.toPath(), new SimpleFileVisitor(){ + + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + File file = path.toFile(); + if (!file.equals(index) && !file.equals(tempIndex)) { + files.add(file); + } + return super.visitFile(path, attrs); + } + + }); + + config.put(RepoIndex.ROOT_URL, directory.getAbsolutePath()); + config.put(RepoIndex.PRETTY, "true"); + repoIndex.index(files, out, config); + } + + renameFile(tempIndex, index); + } + catch (IOException e) { + if (m_log != null) { + m_log.log(LogService.LOG_ERROR, "Unable to create temporary file for new repository index.", e); + } + throw e; + } + catch (InterruptedException e) { + if (m_log != null) { + m_log.log(LogService.LOG_ERROR, "Waiting for next attempt to move temporary repository index failed.", e); + } + // Make sure the thread's administration remains correct... + Thread.currentThread().interrupt(); + } + catch (Exception e) { + if (m_log != null) { + m_log.log(LogService.LOG_ERROR, "Failed to generate new repository index.", e); + } + throw new IOException("Failed to generate new repository index. + (" + e.getMessage() + ")"); + } + } + } + + /** + * Renames a given source file to a new destination file, using Commons-IO. + *

This avoids the problem mentioned in ACE-155.

+ * + * @param source the file to rename; + * @param dest the file to rename to. + */ + private void renameFile(File source, File dest) throws IOException, InterruptedException { + boolean renameOK = false; + int attempts = 0; + while (!renameOK && (attempts++ < 10)) { + try { + renameOK = moveFile(source, dest); + } + catch (IOException e) { + // In all other cases, we assume the source file is still locked and cannot be removed; + Thread.sleep(1000); + } + } + + if (!renameOK) { + if (m_log != null) { + m_log.log(LogService.LOG_ERROR, "Unable to move new repository index to it's final location."); + } + throw new IOException("Could not move temporary index file (" + source.getAbsolutePath() + ") to it's final location (" + dest.getAbsolutePath() + ")"); + } + } + + /** + * Moves a given source file to a destination location, effectively resulting in a rename. + * + * @param source the source file to move; + * @param dest the destination file to move the file to. + * @return true if the move succeeded. + * @throws IOException in case of I/O problems. + */ + private boolean moveFile(File source, File dest) throws IOException { + final int bufferSize = 1024 * 1024; // 1MB + + try (FileInputStream fis = new FileInputStream(source); + FileOutputStream fos = new FileOutputStream(dest); + FileChannel input = fis.getChannel(); + FileChannel output = fos.getChannel()) { + + long size = input.size(); + long pos = 0; + while (pos < size) { + pos += output.transferFrom(input, pos, Math.min(size - pos, bufferSize)); + } + } + + if (source.length() != dest.length()) { + throw new IOException("Failed to move file! Not all contents from '" + source + "' copied to '" + dest + "'!"); + } + + dest.setLastModified(source.lastModified()); + + if (!source.delete()) { + dest.delete(); + throw new IOException("Failed to move file! Source file (" + source + ") locked?"); + } + + return true; + } +} \ No newline at end of file Propchange: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/repoindex/RepoIndexMetadataGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java (original) +++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java Thu Feb 11 11:33:46 2016 @@ -45,11 +45,11 @@ import org.osgi.service.log.LogService; /** * This BundleStore retrieves the files from the file system. Via the Configurator the relative path is set, and all - * bundles and the repository.xml should be retrievable from that path (which will internally be converted to an + * bundles and the index.xml should be retrievable from that path (which will internally be converted to an * absolute path). */ public class BundleFileStore implements BundleStore, ManagedService { - private static final String REPOSITORY_XML = "repository.xml"; + private static final String REPOSITORY_XML = "index.xml"; private static int BUFFER_SIZE = 8 * 1024; private final Object m_lock = new Object(); Modified: ace/trunk/org.apache.ace.obr/storage.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/storage.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/storage.bnd (original) +++ ace/trunk/org.apache.ace.obr/storage.bnd Thu Feb 11 11:33:46 2016 @@ -4,6 +4,6 @@ Private-Package: org.apache.ace.obr.stor org.apache.ace.obr.metadata.util Bundle-Activator: org.apache.ace.obr.storage.file.Activator Export-Package: org.apache.ace.obr.storage -Bundle-Version: 2.0.1 +Bundle-Version: 2.0.2 Bundle-Name: Apache ACE OBR Storage Bundle-Description: Registers a file based BundleStore for the OBR \ No newline at end of file Added: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java?rev=1729811&view=auto ============================================================================== --- ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java (added) +++ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java Thu Feb 11 11:33:46 2016 @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ace.obr.metadata.repoindeximpl; + +import static org.apache.ace.test.utils.TestUtils.UNIT; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.apache.ace.deployment.provider.ArtifactData; +import org.apache.ace.deployment.provider.impl.ArtifactDataImpl; +import org.apache.ace.deployment.util.test.BundleStreamGenerator; +import org.apache.ace.obr.metadata.MetadataGenerator; +import org.apache.ace.obr.metadata.repoindex.RepoIndexMetadataGenerator; +import org.testng.annotations.Test; + +public class RepoIndexMetadataTest { + + private ArtifactData generateBundle(File file, String symbolicName, String version) throws Exception { + // create a mock bundle, which is only used to generate the bundle on disk, and not used for anything else... + ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, -1L, version, file.toURI().toURL(), false); + System.out.println("GETVERSION: " + bundle.getVersion()); + BundleStreamGenerator.generateBundle(bundle); + return bundle; + } + + /** + * Generate metadata index, verify contents + */ + @Test(groups = { UNIT }) + public void generateMetaData() throws Exception { + File dir = File.createTempFile("meta", ""); + dir.delete(); + dir.mkdir(); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.1", "1.0.0"); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.2", "1.0.0"); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.3", "1.0.0"); + MetadataGenerator meta = new RepoIndexMetadataGenerator(); + meta.generateMetadata(dir); + File index = new File(dir, "index.xml"); + assert index.exists() : "No repository index was generated"; + assert index.length() > 0 : "Repository index can not be size 0"; + int count = 0; + String line; + BufferedReader in = new BufferedReader(new FileReader(index)); + while ((line = in.readLine()) != null) { + if (line.contains("")) { + count++; + } + } + in.close(); + assert count == 3 : "Expected 3 resources in the repository index, found " + count + "."; + } + + /** + * Generate a metadata index, remove a bundle, regenerate metadata, verify. + */ + @Test(groups = { UNIT }) + public void updateMetaData() throws Exception { + File dir = File.createTempFile("meta", ""); + dir.delete(); + dir.mkdir(); + File bundle = File.createTempFile("bundle", ".jar", dir); + generateBundle(bundle, "bundle.symbolicname.1", "1.0.0"); + MetadataGenerator meta = new RepoIndexMetadataGenerator(); + meta.generateMetadata(dir); + bundle.delete(); + meta.generateMetadata(dir); + File index = new File(dir, "index.xml"); + assert index.exists() : "No repository index was generated"; + assert index.length() > 0 : "Repository index can not be size 0"; + int count = 0; + String line; + BufferedReader in = new BufferedReader(new FileReader(index)); + while ((line = in.readLine()) != null) { + if (line.contains("")) { + count++; + } + } + in.close(); + assert count == 0 : "Expected 0 resources in the repository index, found " + count + "."; + } + + /** + * Generate metadata index with partially invalid contents, verify contents + */ + @Test(groups = { UNIT }) + public void generatePartiallyInvalidMetaData() throws Exception { + File dir = File.createTempFile("meta", ""); + dir.delete(); + dir.mkdir(); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.1", "1.0.0"); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.2", "1.0_0"); + generateBundle(File.createTempFile("bundle", ".jar", dir), "bundle.symbolicname.3", "1.0.0"); + MetadataGenerator meta = new RepoIndexMetadataGenerator(); + meta.generateMetadata(dir); + File index = new File(dir, "index.xml"); + assert index.exists() : "No repository index was generated"; + assert index.length() > 0 : "Repository index can not be size 0"; + int count = 0; + String line; + BufferedReader in = new BufferedReader(new FileReader(index)); + while ((line = in.readLine()) != null) { + if (line.contains("")) { + count++; + } + } + in.close(); + assert count == 2 : "Expected 2 resources in the repository index, found " + count + "."; + } +} Propchange: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/repoindeximpl/RepoIndexMetadataTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java (original) +++ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java Thu Feb 11 11:33:46 2016 @@ -82,7 +82,7 @@ public class BundleFileStoreTest { m_bundleSubstitute1 = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSub1.jar", 1000); m_bundleSubstitute2 = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSub2.jar", 2000); m_bundleSubstitute3 = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSub3.jar", 3000); - m_bundleRepositoryFile = createFileWithContent(m_directory.getAbsoluteFile(), "repository.xml", 1000); + m_bundleRepositoryFile = createFileWithContent(m_directory.getAbsoluteFile(), "index.xml", 1000); } @AfterMethod(alwaysRun = true) @@ -112,12 +112,12 @@ public class BundleFileStoreTest { } /** - * Test whether retrieving the repository.xml results in a call to the (mock) metadata generator, and the original + * Test whether retrieving the index.xml results in a call to the (mock) metadata generator, and the original * file should correspond with the retrieved file. */ @Test(groups = { UNIT }) public void getRepositoryFile() throws Exception { - InputStream newInputStream = m_bundleStore.get("repository.xml"); + InputStream newInputStream = m_bundleStore.get("index.xml"); assert m_metadata.generated() : "During getting the repository file, the metadata should be regenerated."; byte[] orgContentBuffer = new byte[1000]; @@ -128,7 +128,7 @@ public class BundleFileStoreTest { orgInputStream.read(newContentBuffer); orgInputStream.close(); - assert Arrays.equals(orgContentBuffer, newContentBuffer) : "The original repository.xml content should equal the newly retrieved content."; + assert Arrays.equals(orgContentBuffer, newContentBuffer) : "The original index.xml content should equal the newly retrieved content."; } /** @@ -137,12 +137,12 @@ public class BundleFileStoreTest { */ @Test(groups = { UNIT }) public void updateBundle() throws Exception { - m_bundleStore.get("repository.xml"); + m_bundleStore.get("index.xml"); assert m_metadata.numberOfCalls() == 1 : "The MetadataGenerator should be called once"; m_bundleSubstitute1Larger = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSub1.jar", 2000); - m_bundleStore.get("repository.xml"); + m_bundleStore.get("index.xml"); assert m_metadata.numberOfCalls() == 2 : "The MetadataGenerator should be called twice"; // test specific tear down @@ -156,19 +156,19 @@ public class BundleFileStoreTest { */ @Test(groups = { UNIT }) public void addBundle() throws Exception { - m_bundleStore.get("repository.xml"); + m_bundleStore.get("index.xml"); assert m_metadata.numberOfCalls() == 1 : "The MetadataGenerator should be called once"; File bundleSubstituteX = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSubX.jar", 2000); - m_bundleStore.get("repository.xml"); + m_bundleStore.get("index.xml"); assert m_metadata.numberOfCalls() == 2 : "The MetadataGenerator should be called twice"; bundleSubstituteX.delete(); File bundleSubstituteY = createFileWithContent(m_directory.getAbsoluteFile(), "bundleSubY.jar", 2000); - m_bundleStore.get("repository.xml"); + m_bundleStore.get("index.xml"); assert m_metadata.numberOfCalls() == 3 : "The MetadataGenerator should be called three times"; // test specific tear down Modified: ace/trunk/org.apache.ace.webui.vaadin/bnd.bnd URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/bnd.bnd?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.webui.vaadin/bnd.bnd (original) +++ ace/trunk/org.apache.ace.webui.vaadin/bnd.bnd Thu Feb 11 11:33:46 2016 @@ -10,13 +10,33 @@ org.apache.ace.authentication.api;version=latest,\ org.apache.ace.authentication.impl;version=latest,\ org.apache.felix.http.servlet-api,\ - osgi.core;version=6.0.0 -Private-Package: org.apache.ace.webui.domain,\ + osgi.core;version=6.0.0,\ + biz.aQute.repository,\ + biz.aQute.bnd,\ + org.apache.ace.bnd.registry;version=latest,\ + org.apache.ace.bnd.repository;version=latest +Private-Package: \ + org.apache.ace.webui.domain,\ org.apache.ace.webui.vaadin,\ - org.apache.ace.webui.vaadin.component + org.apache.ace.webui.vaadin.component,\ + org.apache.ace.bnd.registry,\ + org.apache.ace.bnd.repository,\ + org.kxml2.io,\ + org.osgi.impl.bundle.bindex,\ + org.osgi.impl.bundle.obr.resource,\ + org.osgi.service.bindex*,\ + org.osgi.service.indexer*,\ + org.osgi.service.obr,\ + org.osgi.service.repository*,\ + org.xmlpull.v1 + Export-Package: org.apache.ace.webui Include-Resource: resources/ Bundle-Activator: org.apache.ace.webui.vaadin.Activator -Bundle-Version: 1.0.2 +Bundle-Version: 1.0.3 Bundle-Name: Apache ACE WebUI Vaadin -Bundle-Description: Provides the base ACE WebUI based on Vaadin \ No newline at end of file +Bundle-Description: Provides the base ACE WebUI based on Vaadin + +Conditional-Package: \ + biz.aQute*,\ + aQute.*,\ Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java (original) +++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/AddArtifactWindow.java Thu Feb 11 11:33:46 2016 @@ -395,7 +395,6 @@ abstract class AddArtifactWindow extends * the exception */ private void populateArtifactTable(Table dataSource, URL obrBaseUrl) throws Exception { - // retrieve the repository.xml as a stream List obrList = OBRUtil.getAvailableOBREntries(getConnectionFactory(), getArtifactRepository(), obrBaseUrl, m_repositoryXML); if (obrList.isEmpty()) { logDebug("No new data in OBR."); Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/OBRUtil.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/OBRUtil.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/OBRUtil.java (original) +++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/OBRUtil.java Thu Feb 11 11:33:46 2016 @@ -19,35 +19,42 @@ package org.apache.ace.webui.vaadin; -import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.URI; import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; +import org.apache.ace.bnd.registry.RegistryImpl; +import org.apache.ace.bnd.repository.AceUrlConnector; import org.apache.ace.client.repository.helper.bundle.BundleHelper; import org.apache.ace.client.repository.object.ArtifactObject; import org.apache.ace.client.repository.repository.ArtifactRepository; import org.apache.ace.connectionfactory.ConnectionFactory; import org.apache.ace.webui.domain.OBREntry; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; +import org.osgi.framework.Version; +import org.osgi.framework.namespace.IdentityNamespace; +import org.osgi.resource.Capability; +import org.osgi.resource.Requirement; +import org.osgi.resource.Resource; +import org.osgi.service.repository.ContentNamespace; + +import aQute.bnd.deployer.repository.FixedIndexedRepo; +import aQute.bnd.osgi.resource.CapReqBuilder; +import aQute.bnd.service.Registry; /** * Utility methods for handling OBRs. */ public final class OBRUtil { - private static final String XPATH_QUERY = "/repository/resource[@uri]"; /** * Returns all available OBR entries that can be added to the artifact repository. @@ -115,26 +122,6 @@ public final class OBRUtil { } /** - * Gets the actual text from a named item contained in the given node map. - * - * @param map - * the node map to get the named item from; - * @param name - * the name of the item to get. - * @return the text of the named item, can be null in case the named item does not exist, or has no - * text. - */ - private static String getNamedItemText(NamedNodeMap map, String name) { - Node namedItem = map.getNamedItem(name); - if (namedItem == null) { - return null; - } - else { - return namedItem.getTextContent(); - } - } - - /** * Builds a list of all OBR artifacts currently in use. * * @param obrBaseUrl @@ -153,7 +140,7 @@ public final class OBRUtil { for (ArtifactObject ao : artifactObjects) { String artifactURL = ao.getURL(); - if ((artifactURL != null) && artifactURL.startsWith(baseURL)) { + if ((artifactURL != null) /*&& artifactURL.startsWith(baseURL)*/) { // we now know this artifact comes from the OBR we are querying, // so we are interested. fromRepository.add(convertToOBREntry(ao, baseURL)); @@ -163,7 +150,7 @@ public final class OBRUtil { } /** - * Parses the 'repository.xml' from OBR. + * Get all resources from an OSGi R5 repository * * @param obrBaseUrl * the base URL to access the OBR, cannot be null. @@ -171,55 +158,54 @@ public final class OBRUtil { * @throws XPathExpressionException * in case OBR repository is invalid, or incorrect; * @throws IOException - * in case of problems accessing the 'repository.xml' file. + * in case of problems accessing the 'index.xml' file. */ - private static List parseOBRRepository(ConnectionFactory connectionFactory, URL obrBaseUrl, String repositoryName) throws XPathExpressionException, IOException { - InputStream input = null; - NodeList resources = null; - try { - URL url = new URL(obrBaseUrl, repositoryName); - URLConnection connection = connectionFactory.createConnection(url); - // We always want the newest repository.xml file. - connection.setUseCaches(false); - - input = connection.getInputStream(); - - XPath xpath = XPathFactory.newInstance().newXPath(); - // this XPath expressing will find all 'resource' elements which - // have an attribute 'uri'. - resources = (NodeList) xpath.evaluate(XPATH_QUERY, new InputSource(input), XPathConstants.NODESET); + private static List parseOBRRepository(final ConnectionFactory connectionFactory, URL obrBaseUrl, String repositoryName) throws XPathExpressionException, IOException { + FixedIndexedRepo fixedIndexedRepo = new FixedIndexedRepo(); + + AceUrlConnector aceUrlConnector = new AceUrlConnector(connectionFactory); + Registry registry = new RegistryImpl(aceUrlConnector); + fixedIndexedRepo.setRegistry(registry); + + Map properties = new HashMap<>(); + properties.put(FixedIndexedRepo.PROP_LOCATIONS, new URL(obrBaseUrl, repositoryName).toString()); + fixedIndexedRepo.setProperties(properties); + + Requirement requirement = new CapReqBuilder("osgi.identity") + .addDirective("filter", "(&(osgi.identity=*)(version=*)(type=*))") + .buildSyntheticRequirement(); + + Map> sourceResources = fixedIndexedRepo.findProviders(Collections.singleton(requirement)); + if (sourceResources.isEmpty() || sourceResources.get(requirement).isEmpty()) { + return Collections.emptyList(); } - finally { - if (input != null) { - try { - input.close(); - } - catch (IOException e) { - // too bad, no worries. - } - } - } - List obrList = new ArrayList<>(); - for (int nResource = 0; nResource < resources.getLength(); nResource++) { - Node resource = resources.item(nResource); - NamedNodeMap attr = resource.getAttributes(); - - String uri = getNamedItemText(attr, "uri"); - String name = getNamedItemText(attr, "presentationname"); - String symbolicname = getNamedItemText(attr, "symbolicname"); - String version = getNamedItemText(attr, "version"); - - if (name == null || name.equals("")) { - if (symbolicname != null && !symbolicname.equals("")) { - name = symbolicname; - } - else { - name = new File(uri).getName(); - } + Iterator capabilities = sourceResources.get(requirement).iterator(); + while (capabilities.hasNext()) { + Capability capability = capabilities.next(); + + Resource resource = capability.getResource(); + List identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE); + String bsn = null; + Version version = null; + if (identities != null && identities.size() == 1){ + Capability id = identities.get(0); + bsn = (String) id.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE); + version = (Version) id.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); + } + + URI uri = null; + List contentCapabilities = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE); + if (contentCapabilities != null && contentCapabilities.size() == 1) { + Capability content = contentCapabilities.get(0); + uri = (URI) content.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); + } + + if (bsn != null && uri != null) { + obrList.add(new OBREntry(bsn, bsn, version.toString(), uri.toString().substring(obrBaseUrl.toString().length()))); + } else { + throw new IllegalStateException("No Identity or multiple identities"); } - - obrList.add(new OBREntry(name, symbolicname, version, uri)); } return obrList; Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java (original) +++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinServlet.java Thu Feb 11 11:33:46 2016 @@ -63,7 +63,7 @@ public class VaadinServlet extends Abstr private static final String DEFAULT_PASSWORD = ""; private static final URL DEFAULT_ACE_HOST; private static final URL DEFAULT_OBR_URL; - private static final String DEFAULT_OBR_XML = "repository.xml"; + private static final String DEFAULT_OBR_XML = "index.xml"; private static final String DEFAULT_SERVLET_ENDPOINT = "/ace"; private static final int DEFAULT_SESSION_TIMEOUT = 300; // in seconds. private static final double DEFAULT_CACHE_RATE = 1; Modified: ace/trunk/run-client/conf/org.apache.ace.webui.vaadin.cfg URL: http://svn.apache.org/viewvc/ace/trunk/run-client/conf/org.apache.ace.webui.vaadin.cfg?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/run-client/conf/org.apache.ace.webui.vaadin.cfg (original) +++ ace/trunk/run-client/conf/org.apache.ace.webui.vaadin.cfg Thu Feb 11 11:33:46 2016 @@ -10,7 +10,7 @@ ui.authentication.user.password = ff ace.host = http://${org.apache.ace.server}/ # OBR settings obr.url = http://${org.apache.ace.obr}/obr/ -obr.xml = repository.xml +obr.xml = index.xml # Session timeout; due to ACE-528 this is now set in ms! session.timeout = 300000 # Tuning of the artifacts column Modified: ace/trunk/run-server-allinone/conf/org.apache.ace.webui.vaadin.cfg URL: http://svn.apache.org/viewvc/ace/trunk/run-server-allinone/conf/org.apache.ace.webui.vaadin.cfg?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/run-server-allinone/conf/org.apache.ace.webui.vaadin.cfg (original) +++ ace/trunk/run-server-allinone/conf/org.apache.ace.webui.vaadin.cfg Thu Feb 11 11:33:46 2016 @@ -11,7 +11,7 @@ ui.authentication.user.password = ff ace.host = http://${org.apache.ace.server}/ # OBR settings obr.url = http://${org.apache.ace.obr}/obr/ -obr.xml = repository.xml +obr.xml = index.xml # Session timeout; due to ACE-528 this is now set in ms! session.timeout = 300000 # Tuning of the artifacts column Modified: ace/trunk/run-server-allinone/scripts/clear.gogo URL: http://svn.apache.org/viewvc/ace/trunk/run-server-allinone/scripts/clear.gogo?rev=1729811&r1=1729810&r2=1729811&view=diff ============================================================================== --- ace/trunk/run-server-allinone/scripts/clear.gogo (original) +++ ace/trunk/run-server-allinone/scripts/clear.gogo Thu Feb 11 11:33:46 2016 @@ -23,7 +23,7 @@ each ($w lf2d) {$w df2d $it} each ($w ld2t) {$w dd2t $it} # delete artifacts from OBR as well (assuming local OBR is used!)... -r = (repo OBR 'http://localhost:8080/obr/repository.xml') +r = (repo OBR 'http://localhost:8080/obr/index.xml') repo:rm $r # commit and delete the workspace