Ignore:
Timestamp:
09/21/11 16:46:58 (8 months ago)
Author:
delmitz
Branch:
default
Convert:
svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2791
Message:
  • modified script name timestamps to timestamp.
  • modified bundle update.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kraken-core/src/main/java/org/krakenapps/bundle/BundleManagerService.java

    r215 r357  
    6262 */ 
    6363public class BundleManagerService implements SynchronousBundleListener, BundleManager { 
    64         final Logger logger = LoggerFactory.getLogger(BundleManagerService.class.getName()); 
     64        private Logger logger = LoggerFactory.getLogger(BundleManagerService.class); 
    6565 
    6666        private BundleContext context; 
     
    312312                        bundle.stop(); 
    313313                } catch (BundleException e) { 
    314                         e.printStackTrace(); 
     314                        logger.error("kraken core: stopping bundle failed.", e); 
    315315                } 
    316316        } 
     
    330330 
    331331                try { 
     332                        if (!isLocalJar(bundle)) { 
     333                                try { 
     334                                        File before = new File(bundle.getLocation().replace("file://", "")); 
     335                                        File temp = File.createTempFile(before.getName(), "", before.getParentFile()); 
     336                                        temp.delete(); 
     337                                        if (before.renameTo(temp)) { 
     338                                                MavenResolver resolver = new MavenResolver(getLocalRepository(), 
     339                                                                config.getBundleRepositories(), null, getKeyStoreManager()); 
     340                                                MavenArtifact artifact = getArtifact(bundle); 
     341                                                File after = resolver.resolve(artifact); 
     342                                                if (after.exists()) 
     343                                                        temp.delete(); 
     344                                                else 
     345                                                        temp.renameTo(before); 
     346                                        } 
     347                                } catch (MavenResolveException e) { 
     348                                        logger.error("kraken core: maven resolve failed.", e); 
     349                                } catch (IOException e) { 
     350                                        logger.error("kraken core: create temp file failed.", e); 
     351                                } 
     352                        } 
    332353                        bundle.update(); 
    333354                } catch (BundleException e) { 
    334                         e.printStackTrace(); 
    335                 } 
     355                        logger.error("kraken core: updating bundle failed.", e); 
     356                } 
     357        } 
     358 
     359        private boolean isLocalJar(Bundle bundle) { 
     360                File location = new File(bundle.getLocation().replace("file://", "")); 
     361                File krakenDownload = new File(System.getProperty("kraken.download.dir")); 
     362 
     363                while (location.getParentFile() != null) { 
     364                        if (location.equals(krakenDownload)) 
     365                                return false; 
     366                        location = location.getParentFile(); 
     367                } 
     368 
     369                return true; 
     370        } 
     371 
     372        private MavenArtifact getArtifact(Bundle bundle) { 
     373                File location = new File(bundle.getLocation().replace("file://", "")); 
     374                File krakenDownload = new File(System.getProperty("kraken.download.dir")); 
     375 
     376                String groupId = null; 
     377                String artifactId = null; 
     378                Version version = null; 
     379                while (location.getParentFile() != null) { 
     380                        location = location.getParentFile(); 
     381                        if (location.equals(krakenDownload)) 
     382                                break; 
     383 
     384                        String name = location.getName(); 
     385                        if (version == null) 
     386                                version = new Version(name); 
     387                        else if (artifactId == null) 
     388                                artifactId = name; 
     389                        else if (groupId == null) 
     390                                groupId = name; 
     391                        else 
     392                                groupId = name + "." + groupId; 
     393                } 
     394 
     395                return new MavenArtifact(groupId, artifactId, version); 
    336396        } 
    337397 
Note: See TracChangeset for help on using the changeset viewer.