Skip to content

Commit 9c45b60

Browse files
committed
Przygotowanie do v0.4.1
1 parent ea1db94 commit 9c45b60

File tree

7 files changed

+236
-57
lines changed

7 files changed

+236
-57
lines changed

manifest.mf

Lines changed: 0 additions & 3 deletions
This file was deleted.

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@
139139
<manifest>
140140
<addClasspath>true</addClasspath>
141141
<classpathPrefix>lib/</classpathPrefix>
142-
<mainClass>
143-
pl.koder95.eme.Main
144-
</mainClass>
142+
<mainClass>pl.koder95.eme.Main</mainClass>
143+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
144+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
145+
<addExtensions>true</addExtensions>
145146
</manifest>
146147
</archive>
147148
</configuration>

src/main/java/pl/koder95/eme/Main.java

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import pl.koder95.eme.core.spi.CabinetAnalyzer;
3838
import pl.koder95.eme.core.spi.FilingCabinet;
3939
import pl.koder95.eme.dfs.IndexList;
40+
import pl.koder95.eme.git.RepositoryInfo;
4041

4142
import java.text.Collator;
4243
import java.util.Arrays;
@@ -47,7 +48,7 @@
4748
/**
4849
* Klasa uruchamiająca i inicjalizująca podstawowe elementy aplikacji.
4950
* @author Kamil Jan Mularski [@koder95]
50-
* @version 0.4.0, 2020-08-26
51+
* @version 0.4.1, 2021-11-05
5152
* @since 0.0.201
5253
*/
5354
public class Main extends Application {
@@ -63,8 +64,8 @@ public class Main extends Application {
6364
/**
6465
* Domyślny sposób porównywania stringów (polski).
6566
*/
66-
public static final Collator DEFAULT_COLLATOR
67-
= Collator.getInstance(POLISH); //NOI18N
67+
public static final Collator DEFAULT_COLLATOR = Collator.getInstance(POLISH); //NOI18N
68+
6869
private static final String FAV_PATH_START = "pl/koder95/eme/favicon";
6970
/**
7071
* Ścieżka ikony dla okienek.
@@ -77,6 +78,12 @@ public class Main extends Application {
7778
= Pattern.compile("([0-9]*)");
7879

7980
public static void main(String[] args) {
81+
if (args.length == 1) {
82+
if (args[0].equals("-v")) {
83+
System.out.println(Version.get());
84+
System.exit(0);
85+
}
86+
}
8087
Main.launch(args);
8188
}
8289

@@ -93,6 +100,7 @@ public static void releaseMemory() {
93100

94101
@Override
95102
public void init() throws Exception {
103+
RepositoryInfo.get().reload();
96104
super.init();
97105
Arrays.stream(IndexList.values()).forEach(IndexList::load);
98106

@@ -112,31 +120,35 @@ public void init() throws Exception {
112120
public void start(Stage primaryStage) {
113121
primaryStage.getIcons().add(new Image(FAVICON_PATH));
114122
primaryStage.setTitle("eMetrykant " + Version.get());
115-
primaryStage.setScene(new Scene(root));
116-
primaryStage.setOnCloseRequest(event -> System.exit(0));
117-
118-
Stage secondary = new Stage();
119-
secondary.initStyle(StageStyle.UNDECORATED);
123+
Version latestRelease = RepositoryInfo.get().getLatestReleaseVersion();
124+
if (latestRelease.compareTo(Version.get()) > 0) {
125+
primaryStage.initStyle(StageStyle.UNDECORATED);
120126

121-
ProgressIndicator updating = new ProgressIndicator();
122-
Label title = new Label();
123-
Label message = new Label();
124-
updating.progressProperty().bind(task.progressProperty());
125-
title.textProperty().bind(task.titleProperty());
126-
message.textProperty().bind(task.messageProperty());
127+
ProgressIndicator updating = new ProgressIndicator();
128+
Label title = new Label();
129+
Label message = new Label();
130+
updating.progressProperty().bind(task.progressProperty());
131+
title.textProperty().bind(task.titleProperty());
132+
message.textProperty().bind(task.messageProperty());
127133

128-
VBox texts = new VBox(5d, title, message);
129-
texts.setAlignment(Pos.CENTER_LEFT);
130-
VBox progressing = new VBox(updating);
131-
progressing.setAlignment(Pos.CENTER_RIGHT);
132-
HBox root = new HBox(5d, progressing, texts);
133-
root.setAlignment(Pos.CENTER);
134+
VBox texts = new VBox(5d, title, message);
135+
texts.setAlignment(Pos.CENTER_LEFT);
136+
VBox progressing = new VBox(updating);
137+
progressing.setAlignment(Pos.CENTER_RIGHT);
138+
HBox root = new HBox(5d, progressing, texts);
139+
root.setAlignment(Pos.CENTER);
134140

135-
secondary.setScene(new Scene(root));
136-
secondary.setAlwaysOnTop(true);
137-
secondary.setMinWidth(300);
138-
secondary.setMinHeight(150);
139-
secondary.show();
140-
Platform.runLater(task);
141+
primaryStage.setScene(new Scene(root));
142+
primaryStage.setAlwaysOnTop(true);
143+
primaryStage.setMinWidth(300);
144+
primaryStage.setMinHeight(150);
145+
primaryStage.show();
146+
Platform.runLater(task);
147+
}
148+
else {
149+
primaryStage.setScene(new Scene(root));
150+
primaryStage.setOnCloseRequest(event -> System.exit(0));
151+
primaryStage.show();
152+
}
141153
}
142154
}

src/main/java/pl/koder95/eme/Version.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* <a href="https://semver.org/lang/pl/">Wersjonowania semantycznego 2.0.0</a>.
2828
*
2929
* @author Kamil Jan Mularski [@koder95]
30-
* @version 0.4.0, 2020-08-13
30+
* @version 0.4.1, 2021-11-05
3131
* @since 0.2.0
3232
*/
3333
public class Version implements Comparable<Version> {
@@ -157,7 +157,7 @@ public final int compareTo(Version o) {
157157
< 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
158158
*/
159159
else if (!i0.hasNext() && i1.hasNext()) return -1;
160-
else if (i0.hasNext() && !i1.hasNext()) return 1;
160+
return 1;
161161
}
162162
return 0;
163163
}
@@ -223,32 +223,33 @@ public String toString() {
223223
} else return stable;
224224
}
225225

226-
private static Version parse(String str, boolean preRelease) {
226+
private static Version parse0(String str) {
227227
boolean isPreRelease = str.contains("-"),
228228
hasBuildMetadata = str.contains("+");
229229
if (hasBuildMetadata) {
230230
String[] mainParts = str.split(Pattern.quote("+"));
231-
Version r = parse(mainParts[0], preRelease);
232-
r.getBuildMetadata().addAll(
233-
Arrays.asList(mainParts[1].split(Pattern.quote(".")))
234-
);
235-
return r;
231+
Version r = parse0(mainParts[0]);
232+
if (r == null) return null;
233+
return new Version(r.major, r.minor, r.patch, r.preRelease, r.identifiers,
234+
Arrays.asList(mainParts[1].split(Pattern.quote("."))));
236235
} else {
237236
if (isPreRelease) {
238237
// 0 - stable, 1 - pre-release:
239238
String[] nonBuildParts = str.split(Pattern.quote("-"));
240239
String[] preReleaseParts = nonBuildParts[1]
241240
.split(Pattern.quote("."));
242-
Version r = parse(nonBuildParts[0], true);
243-
r.getIdentifiers().addAll(Arrays.asList(preReleaseParts));
244-
return r;
241+
Version r = parse0(nonBuildParts[0]);
242+
if (r == null) return null;
243+
return new Version(r.major, r.minor, r.patch, true, Arrays.asList(preReleaseParts),
244+
Collections.emptyList());
245245
} else {
246246
String[] stableParts = str.split(Pattern.quote("."));
247-
return new Version(
248-
Integer.parseInt(stableParts[0]),
249-
Integer.parseInt(stableParts[1]),
250-
Integer.parseInt(stableParts[2]),
251-
preRelease, new LinkedList<>(), new LinkedList<>());
247+
for (String part : stableParts) {
248+
if (!part.matches("(\\d)+")) {
249+
return null;
250+
}
251+
}
252+
return new Version(Integer.parseInt(stableParts[0]), Integer.parseInt(stableParts[1]), Integer.parseInt(stableParts[2]));
252253
}
253254
}
254255
}
@@ -260,9 +261,7 @@ private static Version parse(String str, boolean preRelease) {
260261
* @return wersja
261262
*/
262263
public static Version parse(String str) {
263-
if (str.startsWith("v"))
264-
return parse(str.substring(1), str.contains("-"));
265-
return parse(str, str.contains("-"));
264+
return parse0(str.startsWith("v")? str.substring(1) : str);
266265
}
267266

268267
/**
@@ -271,13 +270,14 @@ public static Version parse(String str) {
271270
* metody {@link Object#toString()}.
272271
*
273272
* @param klasa klasa, która ma zostać odczytana
274-
* @return wersja
273+
* @return instancja klasy {@link Version} utworzona na podstawie podanej klasy,
274+
* {@code null} — gdy nie można odczytać wersji z podanej klasy
275275
*/
276-
public static Version parse(Class klasa) {
276+
public static Version parse(Class<?> klasa) {
277277
try {
278278
Method get = Arrays.stream(klasa.getMethods())
279279
.reduce(null, (r, c) -> c.getName().equals("get")? c : r);
280-
280+
281281
if (get != null) return parse(get.invoke(null).toString());
282282
return null;
283283
} catch (IllegalAccessException | IllegalArgumentException
@@ -290,6 +290,6 @@ public static Version parse(Class klasa) {
290290
* @return wersja tego programu
291291
*/
292292
public static Version get() {
293-
return parse("0.5.0");
293+
return parse(Main.class.getPackage().getSpecificationVersion());
294294
}
295295
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2018 Kamil Jan Mularski [@koder95]
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package pl.koder95.eme.au;
18+
19+
import pl.koder95.eme.Version;
20+
21+
import java.io.BufferedReader;
22+
import java.io.IOException;
23+
import java.io.InputStreamReader;
24+
import java.nio.file.Path;
25+
26+
/**
27+
* Klasa umożliwia w łatwy sposób zarządzać plikiem JAR na potrzeby aplikacji.
28+
*
29+
* @author Kamil Jan Mularski [@koder95]
30+
* @version 0.4.1, 2021-11-05
31+
* @since 0.4.1
32+
*/
33+
public class JarAnalyzer {
34+
35+
private final Path jar;
36+
37+
public JarAnalyzer(Path jar) {
38+
this.jar = jar;
39+
}
40+
41+
/**
42+
* Pobiera wersję z archiwum JAR poprzez uruchomienie paczki z argumentem {@code -v}.
43+
*
44+
* @return null — jeśli archiwum JAR nie zwraca wersji, w przeciwnym razie zwraca wersję JAR
45+
* @throws IOException w przypadku problemów z odczytaniem strumieni wejścia / wyjścia
46+
*/
47+
public Version getVersion() throws IOException {
48+
if (jar.endsWith(".jar")) {
49+
ProcessBuilder builder = new ProcessBuilder("java", "-jar", jar.toString(), "-v");
50+
Process process = builder.start();
51+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
52+
Version fromLine = Version.parse(reader.readLine());
53+
if (process.isAlive()) process.destroy();
54+
reader.close();
55+
return fromLine;
56+
}
57+
return null;
58+
}
59+
}

src/main/java/pl/koder95/eme/dfs/IndexList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Zawiera wszystkie typy ksiąg i zawierających się w nich zbiorach indeksów.
2929
*
3030
* @author Kamil Jan Mularski [@koder95]
31-
* @version 0.4.0, 2020-08-26
31+
* @version 0.4.1, 2021-11-05
3232
* @since 0.1.11
3333
*/
3434
public enum IndexList implements IndexContainer {
@@ -157,7 +157,7 @@ public void clear() {
157157

158158
private static void loadBooks() {
159159
try {
160-
BOOKS = Book.load(Files.INDICES_XML);
160+
BOOKS = Book.load(Files.INDICES_XML.toFile());
161161
} catch (IOException | SAXException | ParserConfigurationException ex) {
162162
System.err.println(ex);
163163
}

0 commit comments

Comments
 (0)