View Javadoc
1   package fr.ifremer.tutti.ui.swing.update.module;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.TuttiConfiguration;
28  import fr.ifremer.tutti.TuttiConfigurationOption;
29  import fr.ifremer.tutti.ui.swing.TuttiUIContext;
30  import fr.ifremer.tutti.ui.swing.updater.UpdateModule;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.nuiton.jaxx.application.ApplicationIOUtil;
34  import org.nuiton.updater.ApplicationInfo;
35  import org.nuiton.version.Version;
36  import org.nuiton.version.Versions;
37  
38  import java.io.File;
39  
40  import static org.nuiton.i18n.I18n.t;
41  
42  /**
43   * Created on 1/28/15.
44   *
45   * @author Tony Chemit - chemit@codelutin.com
46   * @since 3.13
47   */
48  public class TuttiModuleUpdater extends ModuleUpdaterSupport {
49  
50      /** Logger. */
51      private static final Log log = LogFactory.getLog(TuttiModuleUpdater.class);
52  
53      public TuttiModuleUpdater() {
54          super(UpdateModule.tutti);
55      }
56  
57      @Override
58      protected void onUpdateToDo(TuttiUIContext context, ApplicationInfo info) {
59  
60          if (info != null) {
61              if (log.isInfoEnabled()) {
62                  log.info("Find a updatable module : " + updateModule);
63              }
64          }
65      }
66  
67      @Override
68      public void onUpdateDone(TuttiUIContext context, ApplicationInfo info) {
69  
70          if (log.isInfoEnabled()) {
71              log.info(String.format(
72                      "A tutti update was downloaded (oldVersion: %s, newVersion: %s), will restart application to use it",
73                      info.oldVersion, info.newVersion));
74          }
75  
76          TuttiConfiguration config = context.getConfig();
77  
78          // must remove db cache directory
79          File cacheDirectory = config.getCacheDirectory();
80          ApplicationIOUtil.forceDeleteOnExit(
81                  cacheDirectory,
82                  t("tutti.applicationUpdater.updateDone.deleteDirectory.caches.error", cacheDirectory)
83          );
84  
85          Version oldVersion = Versions.valueOf(info.oldVersion);
86  
87          if (config.isFullLaunchMode() && oldVersion.before(Versions.valueOf("3.7.1"))) {
88  
89              // clean application data source (only if coming from before a 3.7.1 version)
90              if (log.isInfoEnabled()) {
91                  log.info("Remove from configuration tutti.update.application.url: " + config.getUpdateApplicationUrl());
92              }
93              config.getApplicationConfig().setOption(TuttiConfigurationOption.UPDATE_APPLICATION_URL.getKey(), "");
94              config.save();
95  
96          }
97  
98      }
99  
100     @Override
101     public String getLabel() {
102         return t("tutti.update.tutti");
103     }
104 
105 }