Skip to content

Commit 6c35bd2

Browse files
committed
Adicionado arquivo updater.yml (Ainda não é carregado e nem salvo)
Adicionado novo método ao arquivo Searcher: getReleasesUrl Desenvolvendo a classe Updater... Outras mudanças: GitHubSearcher -> Implementação do novo método getReleasesUrl
1 parent 1e7e4c1 commit 6c35bd2

5 files changed

Lines changed: 166 additions & 3 deletions

File tree

src/br/com/blackhubos/eventozero/updater/Updater.java

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,93 @@
1919
*/
2020
package br.com.blackhubos.eventozero.updater;
2121

22+
import com.google.common.base.Optional;
23+
24+
import java.util.logging.Logger;
25+
26+
import br.com.blackhubos.eventozero.EventoZero;
27+
import br.com.blackhubos.eventozero.updater.assets.versions.Version;
28+
import br.com.blackhubos.eventozero.updater.github.searcher.GitHubSearcher;
29+
import br.com.blackhubos.eventozero.updater.searcher.Searcher;
30+
2231
/**
2332
* Classe que irá atualizar tudo
2433
*/
25-
public class Updater {}
34+
public class Updater {
35+
private static final Searcher searcher = new GitHubSearcher();
36+
/**
37+
* Versão alternativa caso não encontre a informada no .YML
38+
*/
39+
private static final String INTERNAL_VERSION = "1.0.1";
40+
private static final String updaterNamespace = "[Updater] ";
41+
42+
private final EventoZero plugin;
43+
private final Optional<Version> current;
44+
private final Logger logger;
45+
46+
private final boolean auto_install;
47+
private final boolean debug;
48+
private final boolean enable;
49+
50+
public Updater(EventoZero plugin) {
51+
/** OBTER VALORES DA CONFIGURAÇÃO **/
52+
53+
this.auto_install = true;
54+
this.debug = false;
55+
this.enable = true;
56+
/** FIM DOS VALORES DA CONFIGURAÇÃO **/
57+
58+
this.plugin = plugin;
59+
this.logger = plugin.getLogger();
60+
61+
String versionString = this.plugin.getDescription().getVersion();
62+
63+
logger.info(String.format("%sProcurando a versão '%s'...", updaterNamespace, versionString));
64+
65+
Optional<Version> versionOptional = searcher.findVersion(versionString);
66+
current = versionOptional;
67+
if (!versionOptional.isPresent()) {
68+
versionOptional = searcher.findVersion(INTERNAL_VERSION);
69+
}
70+
71+
72+
if (versionOptional.isPresent()) {
73+
logger.info(String.format("%sVersão econtrada.", updaterNamespace));
74+
} else {
75+
logger.warning(String.format("%sNão foi possivel encontrar a versão '%s'...", updaterNamespace, versionString));
76+
}
77+
78+
79+
}
80+
81+
public void initCheck() {
82+
// TODO: Verificar versões antigas e atualizar
83+
if (!current.isPresent()) {
84+
logger.info(String.format("%sNão foi possivel verificar as versões (Versão atual: %s)!", updaterNamespace, plugin.getDescription().getVersion()));
85+
if (debug) {
86+
logger.info(String.format("%sVocê pode encontrar todas versões no link a seguir: '%s'!", updaterNamespace, searcher.getReleasesUrl()));
87+
}
88+
return;
89+
}
90+
91+
Optional<Version> latest = searcher.getLatestStableVersion();
92+
93+
if (latest.isPresent()) {
94+
Version latestVersion = latest.get();
95+
if (current.get().isSameVersion(latestVersion)) {
96+
logger.info(String.format("%sVocê está utilizando a versão mais recente do %s! Versão: %s",
97+
updaterNamespace, plugin.getDescription().getName(), current.get().getVersion()));
98+
} else if (current.get().isNewerThan(latestVersion)) {
99+
if (debug) {
100+
logger.warning(String.format("%sOps! Sua versão é mais recente que a ultima disponivel! ", updaterNamespace));
101+
logger.warning(String.format("%sCaso você esteja desenvolvendo uma nova versão ou compilado a partir do repositório, ignore este erro. ", updaterNamespace));
102+
logger.warning(String.format("%sCaso contrário, por favor reporte este erro para nossa equipe!", updaterNamespace));
103+
logger.warning(String.format("%sEnvie a seguinte mensagem para nosta equipe ao reportar o erro:", updaterNamespace));
104+
logger.warning(String.format("%sVersão atual: %s. Ultima versão encontrada: %s", updaterNamespace, current.get().toString(), latestVersion.toString()));
105+
}
106+
}
107+
}
108+
109+
110+
}
111+
}

src/br/com/blackhubos/eventozero/updater/assets/versions/Version.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,35 @@ public String toString() {
179179
public int compareTo(Version anotherVersion) {
180180
return this.getPublishDate().compareTo(anotherVersion.getPublishDate());
181181
}
182+
183+
/**
184+
* Determina se a versão atual é mais nova que a informada
185+
* @see #compareTo(Version)
186+
* @param anotherVersion Versão a comparar
187+
* @return True se a versão atual é mais recente que a informada, false caso seja igual ou mais antiga
188+
*/
189+
public boolean isNewerThan(Version anotherVersion) {
190+
return compareTo(anotherVersion) > 0;
191+
}
192+
193+
/**
194+
* Determina se a versão atual é mais antiga que a informada
195+
* @see #compareTo(Version)
196+
* @param anotherVersion Versão a comparar
197+
* @return True se a versão atual é mais antiga que a informada, false caso seja igual ou mais recente
198+
*/
199+
public boolean isOlderThan(Version anotherVersion) {
200+
return compareTo(anotherVersion) < 0;
201+
}
202+
203+
/**
204+
* Determina se a versão atual é a mesma que a informada
205+
* @see #compareTo(Version)
206+
* @param anotherVersion Versão a comparar
207+
* @return True se a versão atual é a mesma que a informada, false caso seja mais recente ou mais antiga
208+
*/
209+
public boolean isSameVersion(Version anotherVersion) {
210+
return compareTo(anotherVersion) == 0;
211+
}
212+
182213
}

src/br/com/blackhubos/eventozero/updater/github/searcher/GitHubSearcher.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
public class GitHubSearcher implements Searcher {
5252

53+
private static final String GITHUB_RELEASES_URL = "https://github.com/BlackHubOS/EventoZero/releases";
5354
private static final String GITHUB_API_URL = "https://api.github.com/repos/BlackHubOS/EventoZero/";
5455
private static final String RELEASES_PATH = "releases";
5556
private static final String LATEST_PATH = "/latest";
@@ -129,7 +130,7 @@ public Collection<Version> getAllVersion() {
129130
public Optional<Version> findVersion(String tag) {
130131
try {
131132
// Conecta ao URL de todas versões
132-
Optional<Collection<Version>> versions = connect(Optional.of(TAG_PATH+"/"+tag));
133+
Optional<Collection<Version>> versions = connect(Optional.of(TAG_PATH + "/" + tag));
133134

134135
// Verifica se encontrou alguma (NullPointerException cade você?)
135136
if (versions.isPresent()) {
@@ -143,6 +144,11 @@ public Optional<Version> findVersion(String tag) {
143144
return Optional.absent();
144145
}
145146

147+
@Override
148+
public String getReleasesUrl() {
149+
return GITHUB_RELEASES_URL;
150+
}
151+
146152
private Optional<Collection<Version>> connect(Optional<String> additionalUrl) throws IOException, ParseException, java.text.ParseException {
147153
// Formatadores de valor a partir de textos e objetos
148154
MultiTypeFormatter multiFormatter = new MultiTypeFormatter();

src/br/com/blackhubos/eventozero/updater/searcher/Searcher.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* You should have received a copy of the GNU General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*
19-
*/package br.com.blackhubos.eventozero.updater.searcher;
19+
*/
20+
package br.com.blackhubos.eventozero.updater.searcher;
2021

2122
import com.google.common.base.Optional;
2223

@@ -51,4 +52,9 @@ public interface Searcher {
5152
*/
5253
Optional<Version> findVersion(String tag);
5354

55+
/**
56+
* Retorna o link onde o projeto está hospedado
57+
* @return O link onde o projeto está hospedado
58+
*/
59+
String getReleasesUrl();
5460
}

src/updater.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#################################################################################################
2+
# #
3+
# #### # # ##### ## ## ####### ###### ###### ##### ####### ###### #
4+
# ## # # ## # # # ### # # # # ## # # # # #
5+
# ## # # ## # # # # # # # ## # # # # #
6+
# ### # # ### # # # # # # # ### # ## # # #
7+
# ## # # ## # # # # # # # ## # # # # #
8+
# ## ## ## ## # # # # # # # # ## # # # # #
9+
# ##### ## ##### # ### # ###### ##### ##### # ## ###### #
10+
# #
11+
#################################################################################################
12+
13+
# Configuração do Atualizador
14+
15+
# Configuração da verificação de atualizações
16+
check:
17+
# Habilitar verificação de atualizações
18+
## Padrão: true
19+
enable: true
20+
# Ao habilitar você receberá mais mensagens de informação sobre os processos de atualização
21+
# Algumas destas mensagens são avisos uteis de erros e bugs para que nossa equipe possa corrigi-los.
22+
## Padrão: false
23+
debug: false
24+
25+
# Instalar atualizações automaticamente
26+
# Obs: Isto não indica que elas serão aplicadas automaticamente.
27+
# Para aplicar será necessário recarregar o plugin ou reiniciar o servidor
28+
## Padrão: true
29+
auto_install: true
30+
31+
# Caso o auto_install esteja definido como fasle, o diretório abaixo será no qual o sistema
32+
# salvará os arquivos baixados de update
33+
# Ao utilizar o comando '/uc update apply' as atualizações no diretório serão aplicadas!
34+
save_directory: 'updates/'

0 commit comments

Comments
 (0)