felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mccu...@apache.org
Subject svn commit: r615757 - in /felix/trunk: bundleplugin/src/main/java/org/apache/felix/bundleplugin/ maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/
Date Mon, 28 Jan 2008 08:26:31 GMT
Author: mcculls
Date: Mon Jan 28 00:26:29 2008
New Revision: 615757

URL: http://svn.apache.org/viewvc?rev=615757&view=rev
Log:
FELIX-457: remove PathFile class and use URIs instead

Removed:
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PathFile.java
Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrCleanRepo.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
    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
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java Mon
Jan 28 00:26:29 2008
@@ -19,13 +19,11 @@
 package org.apache.felix.bundleplugin;
 
 
-import java.io.File;
 import java.net.URI;
 
 import org.apache.felix.obr.plugin.Config;
 import org.apache.felix.obr.plugin.ObrUpdate;
 import org.apache.felix.obr.plugin.ObrUtils;
-import org.apache.felix.obr.plugin.PathFile;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -82,17 +80,14 @@
         try
         {
             String mavenRepository = localRepository.getBasedir();
-            String artifactPath = localRepository.pathOf( project.getArtifact() );
-            String bundlePath = mavenRepository + File.separator + artifactPath;
-            bundlePath = bundlePath.replace( '\\', '/' );
 
-            URI repositoryXml = ObrUtils.findRepositoryXml( project.getBasedir(), mavenRepository,
obrRepository );
+            URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository
);
             URI obrXml = ObrUtils.findObrXml( project.getResources() );
+            URI bundleJar = ObrUtils.findBundleJar( localRepository, project.getArtifact()
);
 
             Config userConfig = new Config();
 
-            update = new ObrUpdate( new PathFile( repositoryXml.getPath() ), obrXml, project,
bundlePath,
-                mavenRepository, userConfig, log );
+            update = new ObrUpdate( repositoryXml, obrXml, project, bundleJar, mavenRepository,
userConfig, log );
 
             update.updateRepository();
         }

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrCleanRepo.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrCleanRepo.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrCleanRepo.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrCleanRepo.java
Mon Jan 28 00:26:29 2008
@@ -55,7 +55,7 @@
  * Clean an OBR repository by finding and removing missing resources.
  * 
  * @goal clean
- * @phase install
+ * @phase clean
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
@@ -75,14 +75,7 @@
      * @required
      * @readonly
      */
-    private ArtifactRepository localRepository;
-
-    /**
-     * @parameter expression="${project.basedir}"
-     * @required
-     * @readonly
-     */
-    private File basedir;
+    private ArtifactRepository m_localRepo;
 
 
     public void execute() throws MojoExecutionException
@@ -96,7 +89,7 @@
         try
         {
             // Compute local repository location
-            URI repositoryXml = ObrUtils.findRepositoryXml( basedir, localRepository.getBasedir(),
obrRepository );
+            URI repositoryXml = ObrUtils.findRepositoryXml( m_localRepo.getBasedir(), obrRepository
);
             if ( !"file".equals( repositoryXml.getScheme() ) )
             {
                 getLog().error( "The repository URI " + repositoryXml + " is not a local
file" );
@@ -141,7 +134,7 @@
      */
     private Element cleanDocument( Element elem )
     {
-        String localRepoPath = localRepository.getBasedir();
+        String localRepoPath = m_localRepo.getBasedir();
         NodeList nodes = elem.getElementsByTagName( "resource" );
         List toRemove = new ArrayList();
 

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
Mon Jan 28 00:26:29 2008
@@ -41,7 +41,7 @@
 /**
  * deploy the bundle to a remote site.
  * this goal is used when you compile a project with a pom file
- * @goal deployment
+ * @goal deploy
  * @phase deploy
  * @requiresDependencyResolution compile
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
@@ -49,9 +49,8 @@
 
 public class ObrDeploy extends AbstractMojo
 {
-
     /**
-     * setting of maven.
+     * Maven settings.
      * 
      * @parameter expression="${settings}"
      * @require
@@ -70,6 +69,7 @@
      * 
      * @parameter expression="${localRepository}"
      * @required
+     * @readonly
      */
     private ArtifactRepository m_localRepo;
 
@@ -88,25 +88,12 @@
     private WagonManager m_wagonManager;
 
     /**
-     * obr file define by the user.
+     * When true, ignore remote locking.
      * 
      * @parameter expression="${ignore-lock}"
-     * 
      */
     private boolean m_ignoreLock;
 
-    /**
-     * used to store pathfile in local repo.
-     */
-    private String m_fileInLocalRepo;
-
-    /**
-     * Enable/Disable this goal
-     * @description If true evrything the goal do nothing, the goal just skip over 
-     * @parameter expression="${maven.obr.installToRemoteOBR}" default-value="false"
-     */
-    private boolean installToRemoteOBR;
-
 
     /**
      * main method for this goal.
@@ -116,20 +103,10 @@
      */
     public void execute() throws MojoExecutionException, MojoFailureException
     {
-        getLog().info( "Obr-deploy start:" );
-        if ( !installToRemoteOBR )
-        {
-            getLog().info( "maven-obr-plugin:deploy goal is disable due to one of the following
reason:" );
-            getLog().info( " - 'installToRemoteOBR' configuration set to false" );
-            getLog().info( " - JVM property maven.obr.installToRemoteOBR set to false" );
-            return;
-        }
         ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
 
         // locate the obr.xml file
         URI obrXml = ObrUtils.findObrXml( m_project.getResources() );
-
-        // the obr.xml file is not present
         if ( null == obrXml )
         {
             getLog().info( "obr.xml is not present, use default" );
@@ -232,32 +209,13 @@
 
         try
         {
-            repoDescriptorFile = remoteFile.get( m_repositoryName );
+            repoDescriptorFile = remoteFile.get( m_repositoryName, ".xml" );
         }
         catch ( TransferFailedException e )
         {
             getLog().error( "Transfer failed" );
             e.printStackTrace();
             throw new MojoFailureException( "TransferFailedException" );
-
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            // file doesn't exist! create a new one
-            getLog().warn( "file specified does not exist: " + m_repositoryName );
-            getLog().warn( "Create a new repository descriptor file " + m_repositoryName
);
-            try
-            {
-                File f = File.createTempFile( String.valueOf( System.currentTimeMillis()
), null );
-                repoDescriptorFile = new File( f.getParent() + File.separator
-                    + String.valueOf( System.currentTimeMillis() ) + ".xml" );
-            }
-            catch ( IOException e1 )
-            {
-                getLog().error( "canno't create temporary file" );
-                e1.printStackTrace();
-                return;
-            }
         }
         catch ( AuthorizationException e )
         {
@@ -271,33 +229,25 @@
             throw new MojoFailureException( "IOException" );
         }
 
-        Config userConfig = new Config();
-        userConfig.setPathRelative( true );
-        userConfig.setRemotely( true );
+        // get the path to local maven repository
+        String mavenRepository = m_localRepo.getBasedir();
 
-        PathFile file = null;
+        URI repoXml = repoDescriptorFile.toURI();
+        URI bundleJar = ObrUtils.findBundleJar( m_localRepo, m_project.getArtifact() );
 
-        // get the path to local maven repository
-        file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() )
+ File.separator
-            + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) )
);
-        if ( file.isExists() )
-        {
-            m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
-        }
-        else
+        if ( !new File( bundleJar ).exists() )
         {
-            getLog().error(
-                "file not found in local repository: " + m_settings.getLocalRepository()
+ File.separator
-                    + m_localRepo.pathOf( m_project.getArtifact() ) );
+            getLog().error( "file not found in local repository: " + bundleJar );
             return;
         }
 
-        file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
+        Config userConfig = new Config();
+        userConfig.setPathRelative( true );
+        userConfig.setRemotely( true );
 
-        ObrUpdate obrUpdate = new ObrUpdate( file, obrXml, m_project, m_fileInLocalRepo,
PathFile
-            .uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, m_project, bundleJar, mavenRepository,
userConfig, getLog() );
 
-        obrUpdate.updateRepository();
+        update.updateRepository();
 
         // the reposiroty descriptor file is modified, we upload it on the remote repository
         try
@@ -323,6 +273,7 @@
             throw new MojoFailureException( "AuthorizationException" );
         }
         repoDescriptorFile.delete();
+        lockFile.delete();
 
         // we remove lockFile activation
         lockFile = null;
@@ -358,6 +309,6 @@
         }
 
         remoteFile.disconnect();
+        lockFile.delete();
     }
-
 }

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
Mon Jan 28 00:26:29 2008
@@ -47,14 +47,12 @@
  */
 public class ObrDeployFile extends AbstractMojo
 {
-
     /**
-     * setting of maven.
+     * Maven settings.
      * 
      * @parameter expression="${settings}"
      * @require
      */
-
     private Settings m_settings;
 
     /**
@@ -69,6 +67,7 @@
      * 
      * @parameter expression="${localRepository}"
      * @required
+     * @readonly
      */
     private ArtifactRepository m_localRepo;
 
@@ -95,18 +94,12 @@
     private String m_obrFile;
 
     /**
-     * obr file define by the user.
+     * When true, ignore remote locking.
      * 
      * @parameter expression="${ignore-lock}"
-     * 
      */
     private boolean m_ignoreLock;
 
-    /**
-     * used to store pathfile in local repo.
-     */
-    private String m_fileInLocalRepo;
-
 
     /**
      * main method for this goal.
@@ -116,8 +109,6 @@
      */
     public void execute() throws MojoExecutionException, MojoFailureException
     {
-        getLog().info( "Obr-deploy-file start:" );
-
         ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
 
         // locate the obr.xml file
@@ -224,32 +215,13 @@
 
         try
         {
-            repoDescriptorFile = remoteFile.get( m_repositoryName );
+            repoDescriptorFile = remoteFile.get( m_repositoryName, ".xml" );
         }
         catch ( TransferFailedException e )
         {
             getLog().error( "Transfer failed" );
             e.printStackTrace();
             throw new MojoFailureException( "TransferFailedException" );
-
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            // file doesn't exist! create a new one
-            getLog().warn( "file specified does not exist: " + m_repositoryName );
-            getLog().warn( "Create a new repository descriptor file " + m_repositoryName
);
-            try
-            {
-                File f = File.createTempFile( String.valueOf( System.currentTimeMillis()
), null );
-                repoDescriptorFile = new File( f.getParent() + File.separator
-                    + String.valueOf( System.currentTimeMillis() ) + ".xml" );
-            }
-            catch ( IOException e1 )
-            {
-                getLog().error( "canno't create temporary file" );
-                e1.printStackTrace();
-                return;
-            }
         }
         catch ( AuthorizationException e )
         {
@@ -263,33 +235,25 @@
             throw new MojoFailureException( "IOException" );
         }
 
-        Config userConfig = new Config();
-        userConfig.setPathRelative( true );
-        userConfig.setRemotely( true );
+        // get the path to local maven repository
+        String mavenRepository = m_localRepo.getBasedir();
 
-        PathFile file = null;
+        URI repoXml = repoDescriptorFile.toURI();
+        URI bundleJar = ObrUtils.findBundleJar( m_localRepo, m_project.getArtifact() );
 
-        // get the path to local maven repository
-        file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() )
+ File.separator
-            + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) )
);
-        if ( file.isExists() )
-        {
-            m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
-        }
-        else
+        if ( !new File( bundleJar ).exists() )
         {
-            getLog().error(
-                "file not found in local repository: " + m_settings.getLocalRepository()
+ File.separator
-                    + m_localRepo.pathOf( m_project.getArtifact() ) );
+            getLog().error( "file not found in local repository: " + bundleJar );
             return;
         }
 
-        file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
+        Config userConfig = new Config();
+        userConfig.setPathRelative( true );
+        userConfig.setRemotely( true );
 
-        ObrUpdate obrUpdate = new ObrUpdate( file, obrXml, m_project, m_fileInLocalRepo,
PathFile
-            .uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, m_project, bundleJar, mavenRepository,
userConfig, getLog() );
 
-        obrUpdate.updateRepository();
+        update.updateRepository();
 
         // the reposiroty descriptor file is modified, we upload it on the remote repository
         try
@@ -315,6 +279,7 @@
             throw new MojoFailureException( "AuthorizationException" );
         }
         repoDescriptorFile.delete();
+        lockFile.delete();
 
         // we remove lockFile activation
         lockFile = null;
@@ -349,5 +314,6 @@
             throw new MojoFailureException( "AuthorizationException" );
         }
         remoteFile.disconnect();
+        lockFile.delete();
     }
 }

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
Mon Jan 28 00:26:29 2008
@@ -26,13 +26,12 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Settings;
 
 
 /**
  * construct the repository.xml with a project Maven compiled
  *
- * @goal repository
+ * @goal install
  * @phase install
  * @requiresDependencyResolution compile
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
@@ -44,6 +43,7 @@
      * 
      * @parameter expression="${localRepository}"
      * @required
+     * @readonly
      */
     private ArtifactRepository m_localRepo;
 
@@ -51,7 +51,6 @@
      * path to the repository.xml.
      * 
      * @parameter expression="${repository-path}"
-     * @require
      */
     private String m_repositoryPath;
 
@@ -64,27 +63,6 @@
 
     private MavenProject m_project;
 
-    /**
-     * setting of maven.
-     * 
-     * @parameter expression="${settings}"
-     * @require
-     */
-
-    private Settings m_settings;
-
-    /**
-     * Enable/Disable this goal
-     * @description If true evrything the goal do nothing, the goal just skip over 
-     * @parameter expression="${maven.obr.installToLocalOBR}" default-value="true"
-     */
-    private boolean installToLocalOBR;
-
-    /**
-     * path to file in the maven local repository.
-     */
-    private String m_fileInLocalRepo;
-
 
     /**
      * main method for this goal.
@@ -93,89 +71,30 @@
      */
     public void execute() throws MojoExecutionException
     {
-        getLog().info( "Obr Plugin starts:" );
-        if ( !installToLocalOBR )
-        {
-            getLog().info( "maven-obr-plugin:repository goal is disable due to one of the
following reason:" );
-            getLog().info( " - 'installToLocalOBR' configuration set to false" );
-            getLog().info( " - JVM property maven.obr.installToLocalOBR set to false" );
-            return;
-        }
-
-        if ( m_repositoryPath == null )
-        {
-            m_repositoryPath = "file:/" + m_localRepo.getBasedir() + File.separator + "repository.xml";
-            getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath
);
-        }
-
-        PathFile file = new PathFile( m_repositoryPath );
-        if ( file.isExists() )
-        {
-            if ( !m_repositoryPath.startsWith( "file:/" ) )
-            {
-                m_repositoryPath = "file:/" + m_repositoryPath;
-            }
-        }
-
         // locate the obr.xml file
         URI obrXml = ObrUtils.findObrXml( m_project.getResources() );
-
-        // the obr.xml file is not present
         if ( null == obrXml )
         {
             getLog().info( "obr.xml is not present, use default" );
         }
 
         // get the path to local maven repository
-        file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() )
+ File.separator
-            + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) )
);
+        String mavenRepository = m_localRepo.getBasedir();
 
-        if ( file.isExists() )
-        {
-            m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
-        }
-        else
-        {
-            getLog().error(
-                "file not found in local repository: " + m_settings.getLocalRepository()
+ File.separator
-                    + m_localRepo.pathOf( m_project.getArtifact() ) );
-            getLog().error(
-                "file not found in local repository: " + m_localRepo.getBasedir() + File.separator
-                    + m_localRepo.pathOf( m_project.getArtifact() ) );
-            return;
-        }
+        URI repoXml = ObrUtils.findRepositoryXml( mavenRepository, m_repositoryPath );
+        URI bundleJar = ObrUtils.findBundleJar( m_localRepo, m_project.getArtifact() );
 
-        // verify the repository.xml
-        PathFile fileRepo = new PathFile( m_repositoryPath );
-        if ( fileRepo.isRelative() )
+        if ( !new File( bundleJar ).exists() )
         {
-            fileRepo.setBaseDir( m_settings.getLocalRepository() );
-        }
-
-        // create the folder to the repository
-        PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() );
-        if ( !repoExist.isExists() )
-        {
-            fileRepo.createPath();
+            getLog().error( "file not found in local repository: " + bundleJar );
+            return;
         }
 
-        // build the user configuration (use default)
-        Config user = new Config();
+        // use default configuration
+        Config userConfig = new Config();
 
-        getLog().debug( "Maven2 Local File repository = " + fileRepo.getAbsoluteFilename()
);
-        getLog().debug( "OBR repository = " + obrXml );
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, m_project, bundleJar, null, userConfig,
getLog() );
 
-        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, m_fileInLocalRepo,
PathFile
-            .uniformSeparator( m_settings.getLocalRepository() ), user, getLog() );
-        try
-        {
-            obrUpdate.updateRepository();
-        }
-        catch ( MojoExecutionException e )
-        {
-            e.printStackTrace();
-            throw new MojoExecutionException( "MojoFailureException" );
-        }
+        update.updateRepository();
     }
-
 }

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
Mon Jan 28 00:26:29 2008
@@ -22,12 +22,13 @@
 import java.io.File;
 import java.net.URI;
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Settings;
 
 
 /**
@@ -41,10 +42,18 @@
 public class ObrInstallFile extends AbstractMojo
 {
     /**
+     * Component factory for Maven artifacts
+     * 
+     * @component
+     */
+    private ArtifactFactory m_factory;
+
+    /**
      * The local Maven repository.
      * 
      * @parameter expression="${localRepository}"
      * @required
+     * @readonly
      */
     private ArtifactRepository m_localRepo;
 
@@ -52,19 +61,10 @@
      * path to the repository.xml.
      * 
      * @parameter expression="${repository-path}"
-     * @require
      */
     private String m_repositoryPath;
 
     /**
-     * setting of maven.
-     * 
-     * @parameter expression="${settings}"
-     * @require
-     */
-    private Settings m_settings;
-
-    /**
      * Artifact Id.
      * @description symbolic name define by the user
      * @parameter expression="${artifactId}"
@@ -119,8 +119,6 @@
         m_project.setVersion( m_version );
         m_project.setPackaging( m_packaging );
 
-        PathFile fileOut;
-
         if ( m_groupId == null )
         {
             getLog().error( "-DgroupId=VALUE is required" );
@@ -142,56 +140,32 @@
             return;
         }
 
-        // copy the file to the local repository
-        PathFile repoLocal = new PathFile( m_localRepo.getBasedir() );
-
-        // get the target file in mvn repo
-        fileOut = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository()
) + File.separator
-            + m_groupId.replace( '.', File.separatorChar ) + File.separator + m_artifactId
+ File.separator + m_version
-            + File.separator + m_artifactId + "-" + m_version + "." + m_packaging );
-
-        if ( !fileOut.isExists() )
-        {
-            getLog().error( "file doesn't exist: " + fileOut.getAbsoluteFilename() );
-            return;
-        }
-        else
+        // locate the obr.xml file
+        URI obrXml = ObrUtils.toFileURI( m_obrFile );
+        if ( null == obrXml )
         {
-            getLog().info( "Target file: " + fileOut.getAbsoluteFilename() );
+            getLog().info( "obr.xml is not present, use default" );
         }
 
-        if ( m_repositoryPath == null )
-        {
-            m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
-            getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath
);
-        }
+        Artifact bundleArtifact = m_factory.createBuildArtifact( m_groupId, m_artifactId,
m_version, m_packaging );
 
-        PathFile fileRepo = new PathFile( m_repositoryPath );
-        if ( fileRepo.isRelative() )
-        {
-            fileRepo.setBaseDir( m_settings.getLocalRepository() );
-        }
+        // get the path to local maven repository
+        String mavenRepository = m_localRepo.getBasedir();
 
-        // create the folder to the repository
-        PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() );
-        if ( !repoExist.isExists() )
-        {
-            fileRepo.createPath();
-        }
+        URI repoXml = ObrUtils.findRepositoryXml( mavenRepository, m_repositoryPath );
+        URI bundleJar = ObrUtils.findBundleJar( m_localRepo, bundleArtifact );
 
-        URI obrXml = ObrUtils.toFileURI( m_obrFile );
-        if ( null == obrXml )
+        if ( !new File( bundleJar ).exists() )
         {
-            getLog().info( "obr.xml is not present, use default" );
+            getLog().error( "file doesn't exist: " + bundleJar );
+            return;
         }
 
-        // build the user config
+        // use default configuration
         Config userConfig = new Config();
 
-        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, fileOut.getOnlyAbsoluteFilename(),
-            m_localRepo.getBasedir(), userConfig, getLog() );
-        obrUpdate.updateRepository();
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, m_project, bundleJar, null, userConfig,
getLog() );
 
+        update.updateRepository();
     }
-
 }

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=615757&r1=615756&r2=615757&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
Mon Jan 28 00:26:29 2008
@@ -79,7 +79,7 @@
     /**
      * name and path to the bundle jar file.
      */
-    private URI m_bundlePath;
+    private URI m_bundleJar;
 
     /**
      * maven project description.
@@ -117,17 +117,16 @@
      * @param repositoryXml path to the repository descriptor file
      * @param obrXml path and filename to the obr.xml file
      * @param project maven project description
-     * @param bundlePath path to the bundle jar file
+     * @param bundleJar path to the bundle jar file
      * @param mavenRepositoryPath path to the local maven repository
      * @param userConfig user information
      * @param logger plugin logger
      */
-    public ObrUpdate( PathFile repositoryXml, URI obrXml, MavenProject project, String bundlePath,
-        String mavenRepositoryPath, Config userConfig, Log logger )
+    public ObrUpdate( URI repositoryXml, URI obrXml, MavenProject project, URI bundleJar,
String mavenRepositoryPath,
+        Config userConfig, Log logger )
     {
-        // m_localRepo = localRepo;
-        m_bundlePath = ObrUtils.toFileURI( bundlePath );
-        m_repositoryXml = repositoryXml.getFile().toURI(); // FIXME: remove when PathFile
is gone
+        m_bundleJar = bundleJar;
+        m_repositoryXml = repositoryXml;
         m_obrXml = obrXml;
         m_project = project;
         m_logger = logger;
@@ -153,10 +152,9 @@
      */
     public void updateRepository() throws MojoExecutionException
     {
-
-        m_logger.debug( " (f) m_obrXml = " + m_obrXml );
-        m_logger.debug( " (f) m_bundlePath = " + m_bundlePath );
-        m_logger.debug( " (f) m_repositoryXml = " + m_repositoryXml );
+        m_logger.debug( " (f) repositoryXml = " + m_repositoryXml );
+        m_logger.debug( " (f) bundleJar = " + m_bundleJar );
+        m_logger.debug( " (f) obrXml = " + m_obrXml );
 
         m_documentBuilder = initDocumentBuilder();
 
@@ -166,21 +164,21 @@
         }
 
         // get the file size
-        File bundleFile = new File( m_bundlePath );
+        File bundleFile = new File( m_bundleJar );
         if ( bundleFile.exists() )
         {
-            URI bundleURI = m_bundlePath;
+            URI resourceURI = m_bundleJar;
             if ( m_userConfig.isPathRelative() )
             {
-                bundleURI = ObrUtils.getRelativeURI( m_baseURI, bundleURI );
+                resourceURI = ObrUtils.getRelativeURI( m_baseURI, resourceURI );
             }
 
             m_resourceBundle.setSize( String.valueOf( bundleFile.length() ) );
-            m_resourceBundle.setUri( bundleURI.toASCIIString() );
+            m_resourceBundle.setUri( resourceURI.toASCIIString() );
         }
         else
         {
-            m_logger.error( "file doesn't exist: " + m_bundlePath );
+            m_logger.error( "file doesn't exist: " + m_bundleJar );
             return;
         }
 
@@ -210,7 +208,7 @@
         try
         {
             // use bindex to extract bundle information
-            bindexExtractor = new ExtractBindexInfo( m_repositoryXml, m_bundlePath.getPath()
);
+            bindexExtractor = new ExtractBindexInfo( m_repositoryXml, m_bundleJar.getPath()
);
         }
         catch ( MojoExecutionException e )
         {

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=615757&r1=615756&r2=615757&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 Mon
Jan 28 00:26:29 2008
@@ -24,6 +24,8 @@
 import java.util.Collection;
 import java.util.Iterator;
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Resource;
 
 
@@ -40,12 +42,11 @@
 
 
     /**
-     * @param baseDir current base directory
      * @param mavenRepository path to local maven repository
      * @param obrRepository path to specific repository.xml
      * @return URI pointing to correct repository.xml
      */
-    public static URI findRepositoryXml( File baseDir, String mavenRepository, String obrRepository
)
+    public static URI findRepositoryXml( String mavenRepository, String obrRepository )
     {
         // Combine location settings into a single repository location
         if ( null == obrRepository || obrRepository.trim().length() == 0 )
@@ -71,13 +72,7 @@
         // fall-back to file-system approach
         if ( null == uri || !uri.isAbsolute() )
         {
-            File file = new File( obrRepository );
-            if ( !file.isAbsolute() )
-            {
-                file = new File( baseDir, obrRepository );
-            }
-
-            uri = file.toURI();
+            uri = new File( obrRepository ).toURI();
         }
 
         return uri;
@@ -100,6 +95,20 @@
             }
         }
         return null;
+    }
+
+
+    /**
+     * @param repository maven repository
+     * @param artifact maven artifact
+     * @return file URI pointing to artifact in repository
+     */
+    public static URI findBundleJar( ArtifactRepository repository, Artifact artifact )
+    {
+        String baseDir = repository.getBasedir();
+        String artifactPath = repository.pathOf( artifact );
+
+        return toFileURI( baseDir + '/' + artifactPath );
     }
 
 

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java?rev=615757&r1=615756&r2=615757&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java
Mon Jan 28 00:26:29 2008
@@ -169,14 +169,13 @@
     /**
      * get a file from the current repository connected.
      * @param url url to the targeted file
+     * @param suffix suggested file suffix
      * @return  get a file descriptor on the requiered resource
      * @throws IOException if an IO error occurs
-     * @throws TransferFailedException  if the transfer failed 
-     * @throws ResourceDoesNotExistException if the targeted resource doesn't exist
+     * @throws TransferFailedException  if the transfer failed
      * @throws AuthorizationException if the connection authorization failed
      */
-    public File get( String url ) throws IOException, TransferFailedException, ResourceDoesNotExistException,
-        AuthorizationException
+    public File get( String url, String suffix ) throws IOException, TransferFailedException,
AuthorizationException
     {
 
         if ( m_wagon == null )
@@ -185,8 +184,26 @@
             return null;
         }
 
-        File file = File.createTempFile( String.valueOf( System.currentTimeMillis() ), "tmp"
);
-        m_wagon.get( url, file );
+        File file = File.createTempFile( String.valueOf( System.currentTimeMillis() ), suffix
);
+        try
+        {
+            m_wagon.get( url, file );
+        }
+        catch ( TransferFailedException e )
+        {
+            file.delete();
+            throw e;
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            file.delete();
+        }
+        catch ( AuthorizationException e )
+        {
+            file.delete();
+            throw e;
+        }
+
         return file;
     }
 
@@ -240,7 +257,7 @@
      * this method indicates if the targeted file is locked or not.
      * @param remote connection manager
      * @param fileName name targeted
-     * @return  true if thr reuiered file is locked, else false
+     * @return  true if the required file is locked, else false
      * @throws MojoFailureException if the plugin failed
      */
     public boolean isLockedFile( RemoteFileManager remote, String fileName ) throws MojoFailureException
@@ -248,17 +265,17 @@
         File file = null;
         try
         {
-            file = remote.get( fileName + ".lock" );
+            file = remote.get( fileName + ".lock", ".lock" );
+            if ( null != file && file.length() == 0 )
+            {
+                return false;
+            }
+            return true;
         }
         catch ( TransferFailedException e )
         {
             e.printStackTrace();
             throw new MojoFailureException( "TransferFailedException" );
-
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            return false;
         }
         catch ( AuthorizationException e )
         {
@@ -270,11 +287,13 @@
             e.printStackTrace();
             throw new MojoFailureException( "IOException" );
         }
-        if ( file != null && file.length() == 0 )
+        finally
         {
-            return false;
+            if ( null != file )
+            {
+                file.delete();
+            }
         }
-        return true;
     }
 
 }



Mime
View raw message