You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2008/01/27 12:04:51 UTC

svn commit: r615572 - in /felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin: ObrUpdate.java ObrUtils.java

Author: mcculls
Date: Sun Jan 27 03:04:46 2008
New Revision: 615572

URL: http://svn.apache.org/viewvc?rev=615572&view=rev
Log:
Begin move to use standardized URIs

Modified:
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java?rev=615572&r1=615571&r2=615572&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java Sun Jan 27 03:04:46 2008
@@ -74,12 +74,12 @@
     /**
      * name and path to the obr.xml file.
      */
-    private String m_obrXml;
+    private URI m_obrXml;
 
     /**
      * name and path to the bundle jar file.
      */
-    private String m_bundlePath;
+    private URI m_bundlePath;
 
     /**
      * maven project description.
@@ -107,9 +107,9 @@
     private ResourcesBundle m_resourceBundle;
 
     /**
-     * base directory used to relativize bundle URIs.
+     * base URI used to relativize bundle URIs.
      */
-    private PathFile m_baseDir;
+    private URI m_baseURI;
 
 
     /**
@@ -126,9 +126,9 @@
         String mavenRepositoryPath, Config userConfig, Log logger )
     {
         // m_localRepo = localRepo;
-        m_bundlePath = bundlePath;
-        m_repositoryXml = repositoryXml.getUri();
-        m_obrXml = obrXml;
+        m_bundlePath = ObrUtils.toFileURI( bundlePath );
+        m_repositoryXml = repositoryXml.getFile().toURI(); // FIXME: remove when PathFile is gone
+        m_obrXml = ObrUtils.toFileURI( obrXml );
         m_project = project;
         m_logger = logger;
 
@@ -138,11 +138,11 @@
 
         if ( userConfig.isRemotely() )
         {
-            m_baseDir = new PathFile( mavenRepositoryPath );
+            m_baseURI = ObrUtils.toFileURI( mavenRepositoryPath );
         }
         else
         {
-            m_baseDir = repositoryXml;
+            m_baseURI = m_repositoryXml;
         }
     }
 
@@ -166,20 +166,17 @@
         }
 
         // get the file size
-        PathFile pf = new PathFile( m_bundlePath );
-        File bundleFile = pf.getFile();
-        pf.setBaseDir( m_baseDir.getOnlyAbsolutePath() );
+        File bundleFile = new File( m_bundlePath );
         if ( bundleFile.exists() )
         {
-            m_resourceBundle.setSize( String.valueOf( bundleFile.length() ) );
+            URI bundleURI = m_bundlePath;
             if ( m_userConfig.isPathRelative() )
             {
-                m_resourceBundle.setUri( pf.getOnlyRelativeFilename().replace( '\\', '/' ) );
-            }
-            else
-            {
-                m_resourceBundle.setUri( "file:" + m_bundlePath );
+                bundleURI = ObrUtils.getRelativeURI( m_baseURI, bundleURI );
             }
+
+            m_resourceBundle.setSize( String.valueOf( bundleFile.length() ) );
+            m_resourceBundle.setUri( bundleURI.toASCIIString() );
         }
         else
         {
@@ -213,7 +210,7 @@
         try
         {
             // use bindex to extract bundle information
-            bindexExtractor = new ExtractBindexInfo( m_repositoryXml, m_bundlePath );
+            bindexExtractor = new ExtractBindexInfo( m_repositoryXml, m_bundlePath.getPath() );
         }
         catch ( MojoExecutionException e )
         {
@@ -273,20 +270,8 @@
         File fout = new File( m_repositoryXml );
         if ( !fout.exists() )
         {
-            // create the repository.xml
-            try
-            {
-                fout.createNewFile();
-                m_logger.info( "Created " + fout.getAbsolutePath() );
-            }
-            catch ( IOException e )
-            {
-                m_logger.error( "Cannot create file " + fout.getAbsolutePath() );
-                e.printStackTrace();
-                return -1;
-            }
-
             Document doc = m_documentBuilder.newDocument();
+
             // create xml tree
             Date d = new Date();
             d.setTime( System.currentTimeMillis() );
@@ -305,7 +290,7 @@
         }
 
         // now we parse the repository.xml file
-        m_repositoryDoc = parseFile( fout.getAbsolutePath(), m_documentBuilder );
+        m_repositoryDoc = parseFile( m_repositoryXml, m_documentBuilder );
         if ( m_repositoryDoc == null )
         {
             return -1;
@@ -321,7 +306,7 @@
      * @param documentBuilder DocumentBuilder get from xerces
      * @return Document which describe this file
      */
-    private Document parseFile( String filename, DocumentBuilder documentBuilder )
+    private Document parseFile( URI filename, DocumentBuilder documentBuilder )
     {
         if ( documentBuilder == null )
         {
@@ -465,6 +450,7 @@
         DOMSource input = new DOMSource( treeToBeWrite );
 
         File fichier = new File( outputFilename );
+        fichier.getParentFile().mkdirs();
         FileOutputStream flux = null;
         try
         {

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java?rev=615572&r1=615571&r2=615572&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java Sun Jan 27 03:04:46 2008
@@ -34,6 +34,7 @@
  */
 public class ObrUtils
 {
+    private static final String DOT_XML = ".xml";
     private static final String REPO_XML = "repository.xml";
     private static final String OBR_XML = "obr.xml";
 
@@ -51,7 +52,7 @@
         {
             obrRepository = mavenRepository + '/' + REPO_XML;
         }
-        else if ( !obrRepository.endsWith( ".xml" ) )
+        else if ( !obrRepository.toLowerCase().endsWith( DOT_XML ) )
         {
             obrRepository = obrRepository + '/' + REPO_XML;
         }
@@ -103,24 +104,51 @@
 
 
     /**
-     * @param repositoryXml URI pointing to repository.xml
-     * @param bundlePath local path to bundle jarfile
-     * @return relative path to bundle jarfile
+     * @param path filesystem path
+     * @return file URI for the path
      */
-    public static String relativize( URI repositoryXml, String bundlePath )
+    public static URI toFileURI( String path )
+    {
+        if ( null == path )
+        {
+            return null;
+        }
+        else if ( path.startsWith( "file:" ) )
+        {
+            return URI.create( path );
+        }
+        else
+        {
+            return new File( path ).toURI();
+        }
+    }
+
+
+    /**
+     * @param repositoryXml URI pointing to repository.xml, or directory containing it
+     * @param bundleJar URI pointing to bundle jarfile
+     * @return relative URI to bundle jarfile
+     */
+    public static URI getRelativeURI( URI repositoryXml, URI bundleJar )
     {
         try
         {
             String repositoryPath = repositoryXml.getPath();
-            int lastFolderIndex = repositoryPath.lastIndexOf( '/' );
+            if ( repositoryPath.toLowerCase().endsWith( DOT_XML ) )
+            {
+                // remove filename to get containing directory
+                int dirnameIndex = repositoryPath.lastIndexOf( '/' );
+                repositoryPath = repositoryPath.substring( 0, dirnameIndex );
+            }
 
-            URI rootURI = new URI( null, repositoryPath.substring( 0, lastFolderIndex ), null );
+            URI rootURI = new URI( null, repositoryPath, null );
+            URI localURI = new URI( null, bundleJar.getPath(), null );
 
-            return rootURI.relativize( new URI( null, bundlePath, null ) ).toASCIIString();
+            return rootURI.relativize( localURI );
         }
         catch ( Exception e )
         {
-            return bundlePath;
+            return bundleJar;
         }
     }
 }