You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2010/03/19 16:32:19 UTC
svn commit: r925279 [1/3] - in /felix/trunk: bundleplugin/
bundleplugin/src/main/java/org/apache/felix/bundleplugin/
bundleplugin/src/main/java/org/apache/felix/obrplugin/
bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/
bundleplugin/src/t...
Author: gnodet
Date: Fri Mar 19 15:32:17 2010
New Revision: 925279
URL: http://svn.apache.org/viewvc?rev=925279&view=rev
Log:
FELIX-2215: Refactor bundlerepository and maven bundle plugin obr data model
Added:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrIndex.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/DataModelHelper.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Property.java
- copied, changed from r925270, felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CategoryImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Base64Encoder.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RepositoryParser.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/XmlWriter.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
Removed:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/Capability.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/Category.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ExtractBindexInfo.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/PElement.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/Require.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ResourcesBundle.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/BundleInfo.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/CapabilityImpl.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/FilterImpl.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/Manifest.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/ManifestEntry.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/Parameter.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/RepositoryImpl.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/RequirementImpl.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/ResourceImpl.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/StringSet.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/Tag.java
felix/trunk/bundleplugin/src/main/java/org/osgi/impl/bundle/obr/resource/VersionRange.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CategoryImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/FilterImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/IteratorToEnumeration.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Logger.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/MapToDictionary.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/R4Attribute.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/R4Directive.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/R4Export.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/R4Import.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/R4Package.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StringSet.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Util.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/VersionRange.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/FilterImplTest.java
Modified:
felix/trunk/bundleplugin/pom.xml
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/RemoteFileManager.java
felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
felix/trunk/bundlerepository/pom.xml
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Capability.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdmin.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Resource.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CapabilityImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalRepositoryImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/LocalResourceImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ObrCommandImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ObrURLStreamHandlerService.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/PropertyImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/PullParser.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RepositoryAdminImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RepositoryImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/RequirementImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/SystemRepositoryImpl.java
felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/wrapper/CapabilityWrapper.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryAdminTest.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/ResolverImplTest.java
felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/StaxParserTest.java
Modified: felix/trunk/bundleplugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/pom.xml?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/pom.xml (original)
+++ felix/trunk/bundleplugin/pom.xml Fri Mar 19 15:32:17 2010
@@ -64,6 +64,11 @@
<version>2.2.2</version>
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.bundlerepository</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundleAllPlugin.java Fri Mar 19 15:32:17 2010
@@ -426,12 +426,6 @@ public class BundleAllPlugin extends Man
}
- protected String getBundleName( MavenProject project )
- {
- return getBundleName( project.getArtifact() );
- }
-
-
private String getBundleName( Artifact artifact )
{
return getMaven2OsgiConverter().getBundleFileName( artifact );
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Fri Mar 19 15:32:17 2010
@@ -815,7 +815,6 @@ public class BundlePlugin extends Abstra
{
return finalName + '-' + classifier + ".jar";
}
-
return finalName + ".jar";
}
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java Fri Mar 19 15:32:17 2010
@@ -202,7 +202,7 @@ public class ObrCleanRepo extends Abstra
/**
* Open an XML file.
*
- * @param filename : XML file path
+ * @param file : XML file path
* @param constructor DocumentBuilder get from xerces
* @return Document which describes this file
* @throws MojoExecutionException occurs when the given file cannot be opened or is a valid XML file.
Added: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrIndex.java?rev=925279&view=auto
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrIndex.java (added)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrIndex.java Fri Mar 19 15:32:17 2010
@@ -0,0 +1,226 @@
+/*
+ * 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.felix.obrplugin;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.bundlerepository.Property;
+import org.apache.felix.bundlerepository.Resource;
+import org.apache.felix.bundlerepository.impl.DataModelHelperImpl;
+import org.apache.felix.bundlerepository.impl.RepositoryImpl;
+import org.apache.felix.bundlerepository.impl.ResourceImpl;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * Index the content of a maven repository using OBR
+ *
+ * @goal index
+ * @requiresProject false
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public final class ObrIndex extends AbstractMojo {
+
+ /**
+ * OBR Repository.
+ *
+ * @parameter expression="${obrRepository}"
+ */
+ private String obrRepository;
+
+ /**
+ * Template for urls
+ *
+ * @parameter expression="${urlTemplate}"
+ */
+ private String urlTemplate;
+
+ /**
+ * Local Repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ public void execute() throws MojoExecutionException {
+ Log log = getLog();
+ try
+ {
+ log.info("Indexing...");
+
+ String mavenRepository = localRepository.getBasedir();
+ URI mavenRepoUri = new File(mavenRepository).toURI();
+
+ URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository );
+
+ log.info("Repository: " + mavenRepoUri);
+ log.info("OBR xml: " + repositoryXml);
+ log.info("URL template: " + urlTemplate);
+
+ List<File> files = new ArrayList<File>();
+ findAllJars( new File(mavenRepository), files );
+
+ DataModelHelperImpl dmh = new DataModelHelperImpl();
+ RepositoryImpl repository = (RepositoryImpl) dmh.repository( repositoryXml.toURL() );
+ for (File file : files)
+ {
+ try
+ {
+ ResourceImpl resource = (ResourceImpl) dmh.createResource(file.toURI().toURL());
+ if (resource != null)
+ {
+ repository.addResource(resource);
+ doTemplate(mavenRepoUri, file, resource);
+ log.info("Adding resource: " + file);
+ }
+ else
+ {
+ log.info("Ignoring non OSGi bundle: " + file);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Error processing bundle: " + file, e);
+ }
+ }
+ Writer writer = new FileWriter( new File(repositoryXml) );
+ try
+ {
+ dmh.writeRepository( repository, writer );
+ }
+ finally
+ {
+ writer.close();
+ }
+ }
+ catch ( Exception e )
+ {
+ log.warn( "Exception while updating local OBR: " + e.getLocalizedMessage(), e );
+ }
+ }
+
+ protected void doTemplate(URI root, File path, ResourceImpl resource) throws IOException, URISyntaxException
+ {
+ path = path.getAbsoluteFile().getCanonicalFile();
+ String finalUri = root.relativize(path.toURI()).toString();
+ if ("maven".equals(urlTemplate))
+ {
+ String dir = root.relativize(path.toURI()).toString();
+ String[] p = dir.split("/");
+ if (p.length >= 4 && p[p.length-1].startsWith(p[p.length-3] + "-" + p[p.length-2]))
+ {
+ String artifactId = p[p.length-3];
+ String version = p[p.length-2];
+ String classifier;
+ String type;
+ String artifactIdVersion = artifactId + "-" + version;
+ StringBuffer sb = new StringBuffer();
+ if (p[p.length-1].charAt(artifactIdVersion.length()) == '-')
+ {
+ classifier = p[p.length-1].substring(artifactIdVersion.length() + 1, p[p.length-1].lastIndexOf('.'));
+ }
+ else
+ {
+ classifier = null;
+ }
+ type = p[p.length-1].substring(p[p.length-1].lastIndexOf('.') + 1);
+ sb.append("mvn:");
+ for (int j = 0; j < p.length - 3; j++)
+ {
+ if (j > 0)
+ {
+ sb.append('.');
+ }
+ sb.append(p[j]);
+ }
+ sb.append('/').append(artifactId).append('/').append(version);
+ if (!"jar".equals(type) || classifier != null)
+ {
+ sb.append('/');
+ if (!"jar".equals(type))
+ {
+ sb.append(type);
+ }
+ if (classifier != null)
+ {
+ sb.append('/').append(classifier);
+ }
+ }
+ finalUri = sb.toString();
+ }
+ }
+ else
+ {
+ String dir = path.getParentFile().toURI().toURL().toString();
+ if (dir.endsWith("/"))
+ dir = dir.substring(0, dir.length() - 1);
+
+ if (dir.startsWith(root.toString()))
+ dir = dir.substring(root.toString().length());
+
+ String url = urlTemplate.replaceAll("%v", "" + resource.getVersion());
+ url = url.replaceAll("%s", resource.getSymbolicName());
+ url = url.replaceAll("%f", path.getName());
+ url = url.replaceAll("%p", dir);
+ finalUri = url;
+ }
+ resource.put(Resource.URI, finalUri, Property.URI);
+ }
+
+ private final FileFilter filter = new FileFilter() {
+
+ public boolean accept(File pathname) {
+ return pathname.getName().endsWith(".jar");
+ }
+
+ };
+
+
+ private void findAllJars(File mainRoot, List<File> files) {
+ List<File> roots = new ArrayList<File>();
+ roots.add(mainRoot);
+ while (!roots.isEmpty()) {
+ File root = roots.remove(0);
+ File[] children = root.listFiles();
+ if (children != null) {
+ for (File child : children) {
+ if (child.isFile() && filter.accept(child)) {
+ files.add(child);
+ } else if (child.isDirectory()) {
+ roots.add(child);
+ }
+ }
+ }
+ }
+ }
+
+}
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java Fri Mar 19 15:32:17 2010
@@ -40,7 +40,7 @@ import org.apache.maven.project.MavenPro
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public final class ObrInstall extends AbstractMojo
+public final class ObrInstall extends AbstractMojo
{
/**
* OBR Repository.
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java Fri Mar 19 15:32:17 2010
@@ -389,7 +389,7 @@ public final class ObrRemoteClean extend
/**
* Open an XML file.
*
- * @param filename : XML file path
+ * @param file : XML file
* @param constructor DocumentBuilder get from xerces
* @return Document which describes this file
* @throws MojoExecutionException occurs when the given file cannot be opened or is a valid XML file.
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java Fri Mar 19 15:32:17 2010
@@ -20,34 +20,26 @@ package org.apache.felix.obrplugin;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.net.URI;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import org.apache.felix.bundlerepository.Resource;
+import org.apache.felix.bundlerepository.impl.DataModelHelperImpl;
+import org.apache.felix.bundlerepository.impl.PullParser;
+import org.apache.felix.bundlerepository.impl.RepositoryImpl;
+import org.apache.felix.bundlerepository.impl.RepositoryParser;
+import org.apache.felix.bundlerepository.impl.ResourceImpl;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
/**
@@ -57,11 +49,6 @@ import org.xml.sax.SAXException;
public class ObrUpdate
{
/**
- * generate the date format to insert it in repository descriptor file.
- */
- static SimpleDateFormat m_format = new SimpleDateFormat( "yyyyMMddHHmmss.SSS" );
-
- /**
* logger for this plugin.
*/
private Log m_logger;
@@ -87,19 +74,14 @@ public class ObrUpdate
private Config m_userConfig;
/**
- * used to build another xml document.
- */
- private DocumentBuilder m_documentBuilder;
-
- /**
* root on parent document.
*/
- private Document m_repositoryDoc;
+ private RepositoryImpl m_repository;
/**
* used to store bundle information.
*/
- private ResourcesBundle m_resourceBundle;
+ private ResourceImpl m_resourceBundle;
/**
* base URI used to relativize bundle URIs.
@@ -134,8 +116,6 @@ public class ObrUpdate
{
m_baseURI = m_repositoryXml;
}
-
- m_documentBuilder = initDocumentBuilder();
}
@@ -157,13 +137,11 @@ public class ObrUpdate
m_logger.debug( " (f) sourceJar = " + sourceJar );
m_logger.debug( " (f) obrXml = " + m_obrXml );
- if ( m_repositoryDoc == null )
+ if ( m_repository == null )
{
return;
}
- m_resourceBundle = new ResourcesBundle( m_logger );
-
// get the file size
File bundleFile = new File( bundleJar );
if ( bundleFile.exists() )
@@ -187,8 +165,17 @@ public class ObrUpdate
m_logger.info( "Installing " + resourceURI );
}
- m_resourceBundle.setSize( String.valueOf( bundleFile.length() ) );
- m_resourceBundle.setUri( resourceURI.toASCIIString() );
+ try
+ {
+ m_resourceBundle = (ResourceImpl) new DataModelHelperImpl().createResource( bundleJar.toURL() );
+ }
+ catch (IOException e)
+ {
+ throw new MojoExecutionException("Unable to load resource information", e);
+ }
+
+ m_resourceBundle.put( Resource.SIZE, String.valueOf( bundleFile.length() ) );
+ m_resourceBundle.put( Resource.URI, resourceURI.toASCIIString() );
}
else
{
@@ -201,47 +188,51 @@ public class ObrUpdate
{
m_logger.info( "Adding " + m_obrXml );
- // URL url = getClass().getResource("/SchemaObr.xsd");
- // TODO validate obr.xml file
+ try
+ {
+ KXmlParser kxp = new KXmlParser();
+ kxp.setInput(new FileInputStream(new File(m_obrXml)), null);
+ PullParser parser = new PullParser();
+ for (int event = kxp.nextTag(); event != XmlPullParser.START_TAG; event = kxp.nextTag())
+ {
+ if (RepositoryParser.CATEGORY.equals(kxp.getName()))
+ {
+ m_resourceBundle.addCategory(parser.parseCategory(kxp));
+ }
+ else if (RepositoryParser.REQUIRE.equals(kxp.getName()))
+ {
+ m_resourceBundle.addRequire(parser.parseRequire(kxp));
+ }
+ else if (RepositoryParser.CAPABILITY.equals(kxp.getName()))
+ {
+ m_resourceBundle.addCapability(parser.parseCapability(kxp));
+ }
+ else
+ {
+ parser.ignoreTag(kxp);
+ }
+ }
- Document obrXmlDoc = parseFile( m_obrXml, m_documentBuilder );
- if ( obrXmlDoc == null )
+ }
+ catch (Exception e)
{
- return;
+ throw new MojoExecutionException("Unable to parse obr xml: " + m_obrXml, e);
}
-
- Node obrXmlRoot = obrXmlDoc.getDocumentElement();
+ // URL url = getClass().getResource("/SchemaObr.xsd");
+ // TODO validate obr.xml file
// add contents to resource bundle
- sortObrXml( obrXmlRoot );
- }
-
- ExtractBindexInfo bindexExtractor;
- try
- {
- // use bindex to extract bundle information
- bindexExtractor = new ExtractBindexInfo( m_repositoryXml, bundleJar.getPath() );
- }
- catch ( MojoExecutionException e )
- {
- m_logger.error( "unable to build Bindex informations" );
- e.printStackTrace();
-
- throw new MojoExecutionException( "BindexException" );
+ parseObrXml();
}
String sourcePath = relativisePath( sourceJar );
String docPath = relativisePath( docJar );
- m_resourceBundle.construct( m_project, bindexExtractor, sourcePath, docPath );
+// m_resourceBundle.construct( m_project, bindexExtractor, sourcePath, docPath );
+// TODO: rebuild wrt m_project
- Element rootElement = m_repositoryDoc.getDocumentElement();
- if ( !walkOnTree( rootElement ) )
- {
- // the correct resource node was not found, we must create it
- String id = m_resourceBundle.getId();
- searchRepository( rootElement, id );
- }
+ m_repository.addResource( m_resourceBundle );
+ m_repository.setLastModified(System.currentTimeMillis());
}
@@ -265,341 +256,124 @@ public class ObrUpdate
{
m_logger.info( "Writing OBR metadata" );
- writeToFile( m_repositoryXml, m_repositoryDoc );
- }
-
-
- /**
- * init the document builder from xerces.
- * @return DocumentBuilder ready to create new document
- */
- private DocumentBuilder initDocumentBuilder()
- {
- DocumentBuilder documentBuilder = null;
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ File file = null;
+ Writer writer;
try
{
- documentBuilder = factory.newDocumentBuilder();
+ file = File.createTempFile( "repository", ".xml" );
+ writer = new OutputStreamWriter( new FileOutputStream( file ) );
}
- catch ( ParserConfigurationException e )
+ catch ( IOException e )
{
- m_logger.error( "unable to create a new xml document" );
+ m_logger.error( "Unable to write to file: " + file.getName() );
e.printStackTrace();
+ throw new MojoExecutionException( "Unable to write to file: " + file.getName() + " : " + e.getMessage() );
}
- return documentBuilder;
-
- }
-
- /**
- * Parse the repository descriptor file.
- *
- * @return true if the repository file was parsed, otherwise false
- * @throws MojoExecutionException if the plugin failed
- */
- public boolean parseRepositoryXml() throws MojoExecutionException
- {
- File fout = new File( m_repositoryXml );
- if ( !fout.exists() )
+ try
{
- Document doc = m_documentBuilder.newDocument();
-
- // create xml tree
- Date d = new Date();
- d.setTime( System.currentTimeMillis() );
- Element root = doc.createElement( "repository" );
- root.setAttribute( "lastmodified", m_format.format( d ) );
- root.setAttribute( "name", "MyRepository" );
- try
- {
- writeToFile( m_repositoryXml, root );
- }
- catch ( MojoExecutionException e )
- {
- e.printStackTrace();
- throw new MojoExecutionException( "IOException" );
- }
+ new DataModelHelperImpl().writeRepository(m_repository, writer);
}
-
- m_repositoryDoc = parseFile( m_repositoryXml, m_documentBuilder );
-
- return ( null != m_repositoryDoc );
- }
-
-
- /**
- * transform a xml file to a xerces Document.
- * @param filename path to the xml file
- * @param documentBuilder DocumentBuilder get from xerces
- * @return Document which describe this file
- */
- private Document parseFile( URI filename, DocumentBuilder documentBuilder )
- {
- if ( documentBuilder == null )
+ catch ( IOException e )
{
- return null;
+ throw new MojoExecutionException( "Unable to write repository xml", e );
}
- // The document is the root of the DOM tree.
- m_logger.info( "Parsing " + filename );
- Document doc = null;
+
try
{
- doc = documentBuilder.parse( new File( filename ) );
- }
- catch ( SAXException e )
- {
- e.printStackTrace();
- return null;
+ writer.flush();
+ writer.close();
+
+ File outputFile = new File( m_repositoryXml );
+ outputFile.getParentFile().mkdirs();
+ FileUtils.rename( file, outputFile );
}
catch ( IOException e )
{
- m_logger.error( "cannot open file: " + filename );
e.printStackTrace();
- return null;
+ throw new MojoExecutionException( "IOException" );
}
- return doc;
+
}
- /**
- * put the information from obr.xml into ressourceBundle object.
- * @param node Node to the OBR.xml file
+ /**
+ * Parse the repository descriptor file.
+ *
+ * @throws MojoExecutionException if the plugin failed
*/
- private void sortObrXml( Node node )
+ public void parseRepositoryXml() throws MojoExecutionException
{
- if ( node.getNodeName().compareTo( "require" ) == 0 )
+ File fout = new File( m_repositoryXml );
+ if ( !fout.exists() )
{
- Require newRequireNode = new Require();
- NamedNodeMap list = node.getAttributes();
- try
- {
- newRequireNode.setExtend( list.getNamedItem( "extend" ).getNodeValue() );
- newRequireNode.setMultiple( list.getNamedItem( "multiple" ).getNodeValue() );
- newRequireNode.setOptional( list.getNamedItem( "optional" ).getNodeValue() );
- newRequireNode.setFilter( list.getNamedItem( "filter" ).getNodeValue() );
- newRequireNode.setName( list.getNamedItem( "name" ).getNodeValue() );
- }
- catch ( NullPointerException e )
- {
- m_logger
- .error( "the obr.xml file seems to be invalid in a \"require\" tag (one or more attributes are missing)" );
- // e.printStackTrace();
- }
- newRequireNode.setValue( XmlHelper.getTextContent( node ) );
- m_resourceBundle.addRequire( newRequireNode );
+ m_repository = new RepositoryImpl();
+ writeRepositoryXml();
}
- else if ( node.getNodeName().compareTo( "capability" ) == 0 )
+ else
{
- Capability newCapability = new Capability();
try
{
- newCapability.setName( node.getAttributes().getNamedItem( "name" ).getNodeValue() );
+ m_repository = (RepositoryImpl) new DataModelHelperImpl().repository( m_repositoryXml.toURL() );
}
- catch ( NullPointerException e )
+ catch ( Exception e )
{
- m_logger.error( "attribute \"name\" is missing in obr.xml in a \"capability\" tag" );
- e.printStackTrace();
- }
- NodeList list = node.getChildNodes();
- for ( int i = 0; i < list.getLength(); i++ )
- {
- PElement p = new PElement();
- Node n = list.item( i );
- Node item = null;
- // System.err.println(n.getNodeName());
- if ( n.getNodeName().compareTo( "p" ) == 0 )
- {
-
- p.setN( n.getAttributes().getNamedItem( "n" ).getNodeValue() );
- item = n.getAttributes().getNamedItem( "t" );
- if ( item != null )
- {
- p.setT( item.getNodeValue() );
- }
- item = n.getAttributes().getNamedItem( "v" );
- if ( item != null )
- {
- p.setV( item.getNodeValue() );
- }
-
- newCapability.addP( p );
- }
- }
- m_resourceBundle.addCapability( newCapability );
- }
- else if ( node.getNodeName().compareTo( "category" ) == 0 )
- {
- Category newCategory = new Category();
- newCategory.setId( node.getAttributes().getNamedItem( "id" ).getNodeValue() );
- m_resourceBundle.addCategory( newCategory );
- }
- else
- {
- NodeList list = node.getChildNodes();
- for ( int i = 0; i < list.getLength(); i++ )
- {
- sortObrXml( list.item( i ) );
+ throw new MojoExecutionException( "Unable to read repository xml: " + m_repositoryXml, e );
}
}
}
/**
- * write a Node in a xml file.
- * @param outputFilename URI to the output file
- * @param treeToBeWrite Node root of the tree to be write in file
- * @throws MojoExecutionException if the plugin failed
+ * put the information from obr.xml into ressourceBundle object.
*/
- private void writeToFile( URI outputFilename, Node treeToBeWrite ) throws MojoExecutionException
- {
- // init the transformer
- Transformer transformer = null;
- TransformerFactory tfabrique = TransformerFactory.newInstance();
- try
- {
- transformer = tfabrique.newTransformer();
- }
- catch ( TransformerConfigurationException e )
- {
- m_logger.error( "Unable to write to file: " + outputFilename.toString() );
- e.printStackTrace();
- throw new MojoExecutionException( "TransformerConfigurationException" );
- }
-
- Properties proprietes = new Properties();
- proprietes.put( "method", "xml" );
- proprietes.put( "version", "1.0" );
- proprietes.put( "encoding", "ISO-8859-1" );
- proprietes.put( "standalone", "yes" );
- proprietes.put( "indent", "yes" );
- proprietes.put( "omit-xml-declaration", "no" );
- transformer.setOutputProperties( proprietes );
-
- DOMSource input = new DOMSource( treeToBeWrite );
-
- File fichier = null;
- FileOutputStream flux = null;
- try
- {
- fichier = File.createTempFile( "repository", ".xml" );
- flux = new FileOutputStream( fichier );
- }
- catch ( IOException e )
- {
- m_logger.error( "Unable to write to file: " + fichier.getName() );
- e.printStackTrace();
- throw new MojoExecutionException( "Unable to write to file: " + fichier.getName() + " : " + e.getMessage() );
- }
- Result output = new StreamResult( flux );
- try
- {
- transformer.transform( input, output );
- }
- catch ( TransformerException e )
- {
- e.printStackTrace();
- throw new MojoExecutionException( "TransformerException" );
- }
-
+ private void parseObrXml() throws MojoExecutionException {
try
{
- flux.flush();
- flux.close();
-
- File outputFile = new File( outputFilename );
- outputFile.getParentFile().mkdirs();
- FileUtils.rename( fichier, outputFile );
+ InputStream is = new FileInputStream(new File(m_obrXml));
+ try
+ {
+ KXmlParser kxp = new KXmlParser();
+ kxp.setInput(is, null);
+ kxp.nextTag();
+ parseObrXml(kxp);
+ }
+ finally
+ {
+ is.close();
+ }
}
- catch ( IOException e )
+ catch (Exception e)
{
- e.printStackTrace();
- throw new MojoExecutionException( "IOException" );
+ throw new MojoExecutionException("Unable to parse obr xml: " + m_obrXml, e);
}
-
}
-
- /**
- * walk on the tree until the targeted node was found.
- * @param node targeted node
- * @return true if the requiered node was found else false.
- */
- private boolean walkOnTree( Node node )
+ private void parseObrXml(KXmlParser kxp) throws Exception
{
- if ( node.getNodeName().compareTo( "resource" ) == 0 )
- {
- return resource( node );
- }
-
- // look at the repository node (first in the file)
- if ( node.getNodeName().compareTo( "repository" ) == 0 )
+ PullParser parser = new PullParser();
+ while (kxp.getEventType() == XmlPullParser.START_TAG)
{
- Date d = new Date();
- d.setTime( System.currentTimeMillis() );
- NamedNodeMap nList = node.getAttributes();
- Node n = nList.getNamedItem( "lastmodified" );
- n.setNodeValue( m_format.format( d ) );
- }
-
- NodeList list = node.getChildNodes();
- if ( list.getLength() > 0 )
- {
- for ( int i = 0; i < list.getLength(); i++ )
+ if (RepositoryParser.CATEGORY.equals(kxp.getName()))
{
- if ( walkOnTree( list.item( i ) ) )
- {
- return true;
- }
+ m_resourceBundle.addCategory(parser.parseCategory(kxp));
}
- }
-
- return false;
- }
-
-
- /**
- * put the resource bundle in the tree.
- * @param node Node on the xml file
- * @param id id of the bundle ressource
- */
- private void searchRepository( Node node, String id )
- {
- if ( node.getNodeName().compareTo( "repository" ) == 0 )
- {
- node.appendChild( m_resourceBundle.getNode( m_repositoryDoc ) );
- return;
- }
-
- m_logger.info( "Second branch..." );
- NodeList list = node.getChildNodes();
- if ( list.getLength() > 0 )
- {
- for ( int i = 0; i < list.getLength(); i++ )
+ else if (RepositoryParser.REQUIRE.equals(kxp.getName()))
+ {
+ m_resourceBundle.addRequire(parser.parseRequire(kxp));
+ }
+ else if (RepositoryParser.CAPABILITY.equals(kxp.getName()))
+ {
+ m_resourceBundle.addCapability(parser.parseCapability(kxp));
+ }
+ else
{
- searchRepository( list.item( i ), id );
+ kxp.nextTag();
+ parseObrXml(kxp);
}
+ kxp.nextTag();
}
}
- /**
- * compare two node and update the array which compute the smallest free id.
- * @param node : node
- * @return true if the node is the same bundle than the ressourceBundle, else false.
- */
- private boolean resource( Node node )
- {
- // this part save all the id free if we need to add resource
- String id = node.getAttributes().getNamedItem( "id" ).getNodeValue();
- NamedNodeMap map = node.getAttributes();
-
- if ( m_resourceBundle.isSameBundleResource( map.getNamedItem( "symbolicname" ).getNodeValue(), map
- .getNamedItem( "version" ).getNodeValue() ) )
- {
- m_resourceBundle.setId( String.valueOf( id ) );
- node.getParentNode().replaceChild( m_resourceBundle.getNode( m_repositoryDoc ), node );
- return true;
- }
- return false;
- }
}
Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/RemoteFileManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/RemoteFileManager.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/RemoteFileManager.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/RemoteFileManager.java Fri Mar 19 15:32:17 2010
@@ -337,7 +337,6 @@ public class RemoteFileManager
/**
* this method indicates if the targeted file is locked or not.
- * @param remote connection manager
* @param fileName name targeted
* @return true if the required file is locked, else false
* @throws MojoExecutionException
Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BlueprintComponentTest.java Fri Mar 19 15:32:17 2010
@@ -73,6 +73,9 @@ public class BlueprintComponentTest exte
instructions.put("nsh_interface", "foo.bar.Namespace");
instructions.put("nsh_namespace", "ns");
+ instructions.put("Export-Service", "p7.Foo;mk=mv");
+ instructions.put("Import-Service", "org.osgi.service.cm.ConfigurationAdmin;availability:=optional");
+
Properties props = new Properties();
Builder builder = plugin.buildOSGiBundle(project, instructions, props, plugin.getClasspath(project));
Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java Fri Mar 19 15:32:17 2010
@@ -21,21 +21,10 @@ package org.apache.felix.bundleplugin;
*/
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Properties;
-import java.util.jar.Manifest;
-import org.apache.maven.model.Resource;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
@@ -44,9 +33,6 @@ import org.apache.maven.model.Organizati
import aQute.lib.osgi.Analyzer;
import aQute.lib.osgi.Builder;
import aQute.lib.osgi.Jar;
-import org.osgi.framework.Constants;
-import org.osgi.impl.bundle.obr.resource.RepositoryImpl;
-import org.osgi.impl.bundle.obr.resource.BundleInfo;
/**
@@ -73,10 +59,6 @@ public class BundlePluginTest extends Ab
public void testConvertVersionToOsgi()
{
- try {
- new BundleInfo(new RepositoryImpl(new URL("file:.")), new File("/Users/gnodet/.m2/repository/org/apache/felix/karaf/webconsole/org.apache.felix.karaf.webconsole.branding/1.5.0-SNAPSHOT/org.apache.felix.karaf.webconsole.branding-1.5.0-SNAPSHOT.jar")).build();
- } catch(Exception e ) {}
-
String osgiVersion;
osgiVersion = plugin.convertVersionToOsgi( "2.1.0-SNAPSHOT" );
Modified: felix/trunk/bundlerepository/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/pom.xml?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/pom.xml (original)
+++ felix/trunk/bundlerepository/pom.xml Fri Mar 19 15:32:17 2010
@@ -32,6 +32,12 @@
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
<artifactId>org.osgi.service.obr</artifactId>
<version>1.0.2</version>
<optional>true</optional>
@@ -45,7 +51,7 @@
<dependency>
<groupId>net.sf.kxml</groupId>
<artifactId>kxml2</artifactId>
- <version>2.2.2</version>
+ <version>2.3.0</version>
<optional>true</optional>
<exclusions>
<exclusion>
@@ -90,7 +96,8 @@
<Private-Package>
org.kxml2.io,
org.xmlpull.v1,
- org.apache.felix.bundlerepository.impl.*
+ org.apache.felix.bundlerepository.impl.*,
+ org.apache.felix.utils.*
</Private-Package>
<Import-Package>!javax.xml.parsers,!org.xml.sax,org.osgi.service.log;resolution:=optional,org.osgi.service.obr;resolution:=optional,javax.xml.stream;resolution:=optional,*</Import-Package>
<DynamicImport-Package>org.apache.felix.shell</DynamicImport-Package>
Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Capability.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Capability.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Capability.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Capability.java Fri Mar 19 15:32:17 2010
@@ -49,6 +49,13 @@ import java.util.Map;
*/
public interface Capability
{
+
+ String BUNDLE = "bundle";
+ String FRAGMENT = "fragment";
+ String PACKAGE = "package";
+ String SERVICE = "service";
+ String EXECUTIONENVIRONMENT = "ee";
+
/**
* Return the name of the capability.
*
@@ -56,12 +63,19 @@ public interface Capability
String getName();
/**
- * Return the set of properties.
+ * Return the properties of this capability
*
- * Notice that the value of the properties is a list of values.
+ * @return
+ */
+ Property[] getProperties();
+
+ /**
+ * Return the map of properties.
*
- * @return a Map<String,List>
+ * @return a Map<String,Object>
*/
- Map getProperties();
+ Map getPropertiesAsMap();
+
+
}
\ No newline at end of file
Added: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/DataModelHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/DataModelHelper.java?rev=925279&view=auto
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/DataModelHelper.java (added)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/DataModelHelper.java Fri Mar 19 15:32:17 2010
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ */
+/*
+ * $Header: /cvshome/build/org.osgi.service.obr/src/org/osgi/service/obr/Requirement.java,v 1.4 2006/03/16 14:56:17 hargrave Exp $
+ *
+ * Copyright (c) OSGi Alliance (2006). All Rights Reserved.
+ *
+ * Licensed 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.
+ */
+
+// This document is an experimental draft to enable interoperability
+// between bundle repositories. There is currently no commitment to
+// turn this draft into an official specification.
+package org.apache.felix.bundlerepository;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Map;
+import java.util.jar.Attributes;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Filter;
+
+public interface DataModelHelper {
+
+ /**
+ * Create a simple requirement to be used for selection
+ * @param name
+ * @param filter
+ * @return
+ * @throws org.osgi.framework.InvalidSyntaxException
+ */
+ Requirement requirement(String name, String filter);
+
+ /**
+ * Create an extender filter supporting the SUBSET, SUPERSET and other extensions
+ *
+ * @param filter the string filter
+ * @return
+ * @throws org.osgi.framework.InvalidSyntaxException
+ */
+ Filter filter(String filter);
+
+ /**
+ * Create a repository from the specified URL.
+ *
+ * @param repository
+ * @return
+ * @throws Exception
+ */
+ Repository repository(URL repository) throws Exception;
+
+ /**
+ * Create a repository for the given set of resources.
+ * Such repositories can be used to create a resolver
+ * that would resolve on a subset of available resources
+ * instead of all of them.
+ *
+ * @param resources an array of resources
+ * @return a repository containing the given resources
+ */
+ Repository repository(Resource[] resources);
+
+ /**
+ * Create a capability
+ *
+ * @param name name of this capability
+ * @param properties the properties
+ * @return a new capability with the specified name and properties
+ */
+ Capability capability(String name, Map properties);
+
+ /**
+ * Create a resource corresponding to the given bundle.
+ *
+ * @param bundle the bundle
+ * @return the corresponding resource
+ */
+ Resource createResource(Bundle bundle);
+
+ /**
+ * Create a resource for the bundle located at the
+ * given location.
+ *
+ * @param bundleUrl the location of the bundle
+ * @return the corresponding resource
+ * @throws IOException
+ */
+ Resource createResource(URL bundleUrl) throws IOException;
+
+ /**
+ * Create a resource corresponding to the given manifest
+ * entries.
+ *
+ * @param attributes the manifest headers
+ * @return the corresponding resource
+ */
+ Resource createResource(Attributes attributes);
+
+ //===========================
+ //== XML serialization ==
+ //===========================
+
+ Repository readRepository(String xml) throws Exception;
+
+ Repository readRepository(Reader reader) throws Exception;
+
+ Resource readResource(String xml) throws Exception;
+
+ Resource readResource(Reader reader) throws Exception;
+
+ Capability readCapability(String xml) throws Exception;
+
+ Capability readCapability(Reader reader) throws Exception;
+
+ Requirement readRequirement(String xml) throws Exception;
+
+ Requirement readRequirement(Reader reader) throws Exception;
+
+ Property readProperty(String xml) throws Exception;
+
+ Property readProperty(Reader reader) throws Exception;
+
+ String writeRepository(Repository repository);
+
+ void writeRepository(Repository repository, Writer writer) throws IOException;
+
+ String writeResource(Resource resource);
+
+ void writeResource(Resource resource, Writer writer) throws IOException;
+
+ String writeCapability(Capability capability);
+
+ void writeCapability(Capability capability, Writer writer) throws IOException;
+
+ String writeRequirement(Requirement requirement);
+
+ void writeRequirement(Requirement requirement, Writer writer) throws IOException;
+
+ String writeProperty(Property property);
+
+ void writeProperty(Property property, Writer writer) throws IOException;
+
+}
Copied: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Property.java (from r925270, felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CategoryImpl.java)
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Property.java?p2=felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Property.java&p1=felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CategoryImpl.java&r1=925270&r2=925279&rev=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CategoryImpl.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Property.java Fri Mar 19 15:32:17 2010
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -16,19 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.bundlerepository.impl;
+package org.apache.felix.bundlerepository;
-public class CategoryImpl
+public interface Property
{
- String m_id = null;
- public void setId(String id)
- {
- m_id = id;
- }
-
- public String getId()
- {
- return m_id;
- }
-}
\ No newline at end of file
+ String VERSION = "version";
+ String URL = "url";
+ String URI = "uri";
+ String LONG = "long";
+ String DOUBLE = "double";
+ String SET = "set";
+
+ String getName();
+
+ String getType();
+
+ String getValue();
+
+ Object getConvertedValue();
+
+}
Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdmin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdmin.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdmin.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/RepositoryAdmin.java Fri Mar 19 15:32:17 2010
@@ -40,9 +40,7 @@
package org.apache.felix.bundlerepository;
import java.net.URL;
-import java.util.Map;
-import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
/**
@@ -171,50 +169,10 @@ public interface RepositoryAdmin
Repository getLocalRepository();
/**
- * Create a simple requirement to be used for selection
- * @param name
- * @param filter
- * @return
- * @throws InvalidSyntaxException
- */
- Requirement requirement(String name, String filter) throws InvalidSyntaxException;
-
- /**
- * Create an extender filter supporting the SUBSET, SUPERSET and other extensions
+ * Return a helper to perform various operations on the data model
*
- * @param filter the string filter
- * @return
- * @throws InvalidSyntaxException
- */
- Filter filter(String filter) throws InvalidSyntaxException;
-
- /**
- * Create a repository from the specified URL.
- *
- * @param repository
* @return
- * @throws Exception
- */
- Repository repository(URL repository) throws Exception;
-
- /**
- * Create a repository for the given set of resources.
- * Such repositories can be used to create a resolver
- * that would resolve on a subset of available resources
- * instead of all of them.
- *
- * @param resources an array of resources
- * @return a repository containing the given resources
- */
- Repository repository(Resource[] resources);
-
- /**
- * Create a capability
- *
- * @param name name of this capability
- * @param properties the properties
- * @return a new capability with the specified name and properties
*/
- Capability capability(String name, Map properties);
+ DataModelHelper getHelper();
}
\ No newline at end of file
Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Resource.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Resource.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Resource.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/Resource.java Fri Mar 19 15:32:17 2010
@@ -48,8 +48,6 @@ import org.osgi.framework.Version;
*
* Resources have capabilities and requirements. All a resource's requirements
* must be satisfied before it can be installed.
- *
- * @version $Revision: 1.5 $
*/
public interface Resource
{
@@ -79,25 +77,68 @@ public interface Resource
final String CATEGORY = "category";
- // get readable name
+ final String MANIFEST_VERSION = "manifestversion";
+ /**
+ * Get all resource properties
+ * @return
+ */
Map getProperties();
- String getSymbolicName();
+ /**
+ * Shortcut for {{getProperties().get(ID)}}
+ * @return
+ */
+ String getId();
- String getPresentationName();
+ /**
+ * Shortcut for {{getProperties().get(SYMBOLIC_NAME)}}
+ * @return
+ */
+ String getSymbolicName();
+ /**
+ * Shortcut for {{getProperties().get(VERSION)}}
+ * @return
+ */
Version getVersion();
- String getId();
+ /**
+ * Shortcut for {{getProperties().get(PRESENTATION_NAME)}}
+ * @return
+ */
+ String getPresentationName();
+ /**
+ * Shortcut for {{getProperties().get(URI)}}
+ * @return
+ */
String getURI();
- Requirement[] getRequirements();
+ /**
+ * Shortcut for {{getProperties().get(SIZE)}}
+ * @return
+ */
+ Long getSize();
+
+ /**
+ * Retrieve this resource categories
+ * @return
+ */
+ String[] getCategories();
+ /**
+ * Retrieve the capabilities
+ * @return
+ */
Capability[] getCapabilities();
- String[] getCategories();
+ /**
+ * Retrieve the requirements
+ *
+ * @return
+ */
+ Requirement[] getRequirements();
/**
* Returns whether this resource is a local one or not.
Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Activator.java Fri Mar 19 15:32:17 2010
@@ -21,6 +21,7 @@ package org.apache.felix.bundlerepositor
import java.util.Hashtable;
import org.apache.felix.bundlerepository.impl.wrapper.Wrapper;
+import org.apache.felix.utils.log.Logger;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.apache.felix.bundlerepository.RepositoryAdmin;
@@ -29,15 +30,44 @@ import org.osgi.service.url.URLStreamHan
public class Activator implements BundleActivator
{
- private transient BundleContext m_context = null;
+ private static BundleContext context = null;
+ private static Logger logger = new Logger(null);
private transient RepositoryAdminImpl m_repoAdmin = null;
+
+ public static BundleContext getContext()
+ {
+ return context;
+ }
+
+ static void setContext(BundleContext context)
+ {
+ Activator.context = context;
+ }
+
+ public static void log(int level, String message)
+ {
+ if (logger != null)
+ {
+ logger.log(level, message);
+ }
+ }
+
+ public static void log(int level, String message, Throwable exception)
+ {
+ if (logger != null)
+ {
+ logger.log(level, message, exception);
+ }
+ }
+
public void start(BundleContext context)
{
- m_context = context;
+ Activator.context = context;
+ Activator.logger = new Logger(context);
// Register bundle repository service.
- m_repoAdmin = new RepositoryAdminImpl(m_context, new Logger(m_context));
+ m_repoAdmin = new RepositoryAdminImpl(context, logger);
context.registerService(
RepositoryAdmin.class.getName(),
m_repoAdmin, null);
@@ -62,7 +92,7 @@ public class Activator implements Bundle
// wrapper for the bundle repository service.
context.registerService(
org.apache.felix.shell.Command.class.getName(),
- new ObrCommandImpl(m_context, m_repoAdmin), null);
+ new ObrCommandImpl(Activator.context, m_repoAdmin), null);
}
catch (Throwable th)
{
@@ -74,7 +104,7 @@ public class Activator implements Bundle
Hashtable dict = new Hashtable();
dict.put(URLConstants.URL_HANDLER_PROTOCOL, "obr");
context.registerService(URLStreamHandlerService.class.getName(),
- new ObrURLStreamHandlerService(m_context, m_repoAdmin), dict);
+ new ObrURLStreamHandlerService(Activator.context, m_repoAdmin), dict);
}
catch (Exception e)
{
Added: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Base64Encoder.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Base64Encoder.java?rev=925279&view=auto
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Base64Encoder.java (added)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/Base64Encoder.java Fri Mar 19 15:32:17 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.felix.bundlerepository.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class Base64Encoder
+{
+ private static final byte encTab[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
+ 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,
+ 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31,
+ 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f };
+
+ public static String base64Encode(String s) throws IOException
+ {
+ return encode(s.getBytes(), 0);
+ }
+
+ /**
+ * Encode a raw byte array to a Base64 String.
+ *
+ * @param in Byte array to encode.
+ * @param len Length of Base64 lines. 0 means no line breaks.
+ **/
+ public static String encode(byte[] in, int len) throws IOException
+ {
+ ByteArrayOutputStream baos = null;
+ ByteArrayInputStream bais = null;
+ try
+ {
+ baos = new ByteArrayOutputStream();
+ bais = new ByteArrayInputStream(in);
+ encode(bais, baos, len);
+ // ASCII byte array to String
+ return (new String(baos.toByteArray()));
+ }
+ finally
+ {
+ if (baos != null)
+ {
+ baos.close();
+ }
+ if (bais != null)
+ {
+ bais.close();
+ }
+ }
+ }
+
+ public static void encode(InputStream in, OutputStream out, int len)
+ throws IOException
+ {
+
+ // Check that length is a multiple of 4 bytes
+ if (len % 4 != 0)
+ {
+ throw new IllegalArgumentException("Length must be a multiple of 4");
+ }
+
+ // Read input stream until end of file
+ int bits = 0;
+ int nbits = 0;
+ int nbytes = 0;
+ int b;
+
+ while ((b = in.read()) != -1)
+ {
+ bits = (bits << 8) | b;
+ nbits += 8;
+ while (nbits >= 6)
+ {
+ nbits -= 6;
+ out.write(encTab[0x3f & (bits >> nbits)]);
+ nbytes++;
+ // New line
+ if (len != 0 && nbytes >= len)
+ {
+ out.write(0x0d);
+ out.write(0x0a);
+ nbytes -= len;
+ }
+ }
+ }
+
+ switch (nbits)
+ {
+ case 2:
+ out.write(encTab[0x3f & (bits << 4)]);
+ out.write(0x3d); // 0x3d = '='
+ out.write(0x3d);
+ break;
+ case 4:
+ out.write(encTab[0x3f & (bits << 2)]);
+ out.write(0x3d);
+ break;
+ }
+
+ if (len != 0)
+ {
+ if (nbytes != 0)
+ {
+ out.write(0x0d);
+ out.write(0x0a);
+ }
+ out.write(0x0d);
+ out.write(0x0a);
+ }
+ }
+}
\ No newline at end of file
Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CapabilityImpl.java?rev=925279&r1=925278&r2=925279&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CapabilityImpl.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/CapabilityImpl.java Fri Mar 19 15:32:17 2010
@@ -21,17 +21,32 @@ package org.apache.felix.bundlerepositor
import java.util.*;
import org.apache.felix.bundlerepository.Capability;
-import org.apache.felix.bundlerepository.Resource;
+import org.apache.felix.bundlerepository.Property;
public class CapabilityImpl implements Capability
{
private String m_name = null;
private final Map m_map = new HashMap();
+ private final List m_list = new ArrayList();
public CapabilityImpl()
{
}
+ public CapabilityImpl(String name)
+ {
+ setName(name);
+ }
+
+ public CapabilityImpl(String name, PropertyImpl[] properties)
+ {
+ setName(name);
+ for (int i = 0; properties != null && i < properties.length; i++)
+ {
+ addProperty(properties[i]);
+ }
+ }
+
public String getName()
{
return m_name;
@@ -42,19 +57,30 @@ public class CapabilityImpl implements C
m_name = name.intern();
}
- public Map getProperties()
+ public Map getPropertiesAsMap()
{
return m_map;
}
- protected void addP(PropertyImpl prop)
+ public Property[] getProperties()
+ {
+ return (Property[]) m_list.toArray(new Property[m_list.size()]);
+ }
+
+ public void addProperty(Property prop)
+ {
+ m_map.put(prop.getName().toLowerCase(), prop.getConvertedValue());
+ m_list.add(prop);
+ }
+
+ public void addProperty(String name, String value)
{
- addP(prop.getN(), prop.getV());
+ addProperty(name, null, value);
}
- protected void addP(String name, Object value)
+ public void addProperty(String name, String type, String value)
{
- m_map.put(name.toLowerCase(), value);
+ addProperty(new PropertyImpl(name, type, value));
}
public String toString()