Skip to content

Commit 815cb86

Browse files
committed
Add mac and linux support
1 parent c27585d commit 815cb86

File tree

10 files changed

+170
-13
lines changed

10 files changed

+170
-13
lines changed

pom.xml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1515
<java.version>11</java.version>
1616

17+
<assembly.file>default.xml</assembly.file>
18+
1719
<javafx.version>11.0.2</javafx.version>
1820
<slf4j-api.version>2.0.9</slf4j-api.version>
1921
<logback-classic.version>1.4.11</logback-classic.version>
@@ -141,7 +143,7 @@
141143
</goals>
142144
<configuration>
143145
<descriptors>
144-
<descriptor>src/assembly/zip.xml</descriptor>
146+
<descriptor>src/assembly/${assembly.file}</descriptor>
145147
</descriptors>
146148
<appendAssemblyId>false</appendAssemblyId>
147149
<finalName>GitWave</finalName>
@@ -152,4 +154,43 @@
152154

153155
</plugins>
154156
</build>
157+
158+
<profiles>
159+
<profile>
160+
<id>windows</id>
161+
<activation>
162+
<os>
163+
<family>windows</family>
164+
</os>
165+
</activation>
166+
<properties>
167+
<assembly.file>zipWindows.xml</assembly.file>
168+
</properties>
169+
</profile>
170+
171+
<profile>
172+
<id>unix</id>
173+
<activation>
174+
<os>
175+
<family>unix</family>
176+
</os>
177+
</activation>
178+
<properties>
179+
<assembly.file>zipUnix.xml</assembly.file>
180+
</properties>
181+
</profile>
182+
183+
<profile>
184+
<id>mac</id>
185+
<activation>
186+
<os>
187+
<family>mac</family>
188+
</os>
189+
</activation>
190+
<properties>
191+
<assembly.file>zipUnix.xml</assembly.file>
192+
</properties>
193+
</profile>
194+
195+
</profiles>
155196
</project>

src/assembly/zipUnix.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
4+
5+
<id>zip-assembly</id>
6+
7+
<formats>
8+
<format>zip</format>
9+
</formats>
10+
11+
<fileSets>
12+
<fileSet>
13+
<directory>target/javaImage</directory>
14+
<outputDirectory>javaImage</outputDirectory>
15+
</fileSet>
16+
<fileSet>
17+
<includes>
18+
<include>NOTICE.txt</include>
19+
<include>LICENSE.md</include>
20+
<include>README.md</include>
21+
</includes>
22+
<outputDirectory>/</outputDirectory>
23+
</fileSet>
24+
<fileSet>
25+
<directory>tools</directory>
26+
<includes>
27+
<include>GitWave.sh</include>
28+
</includes>
29+
<outputDirectory>/</outputDirectory>
30+
</fileSet>
31+
</fileSets>
32+
</assembly>
File renamed without changes.

src/main/java/com/github/introfog/gitwave/GitWaveLauncher.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.github.introfog.gitwave;
1818

1919
import com.github.introfog.gitwave.model.AppConfig;
20+
import com.github.introfog.gitwave.model.OsRecogniser;
2021
import com.github.introfog.gitwave.model.StageFactory;
2122

2223
import javafx.application.Application;
@@ -27,9 +28,11 @@ public class GitWaveLauncher extends Application {
2728
public void start(Stage stage) {
2829
StageFactory.createPrimaryExecuteWindow(stage).getStage().show();
2930
AppConfig.getInstance().setHostServices(getHostServices());
30-
final String pathToGitBashExe = AppConfig.getInstance().getPathToGitBashExe();
31-
if (pathToGitBashExe == null || pathToGitBashExe.isEmpty()) {
32-
StageFactory.createModalSetupWindow().getStage().showAndWait();
31+
if (!OsRecogniser.isCurrentOsUnixLike()) {
32+
final String pathToGitBashExe = AppConfig.getInstance().getPathToGitBashExe();
33+
if (pathToGitBashExe == null || pathToGitBashExe.isEmpty()) {
34+
StageFactory.createModalSetupWindow().getStage().showAndWait();
35+
}
3336
}
3437
}
3538

src/main/java/com/github/introfog/gitwave/controller/SettingsController.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.github.introfog.gitwave.model.AppConfig;
2020
import com.github.introfog.gitwave.model.DialogFactory;
21+
import com.github.introfog.gitwave.model.OsRecogniser;
2122
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
2223

2324
import java.io.File;
@@ -45,16 +46,28 @@ public class SettingsController extends BaseController {
4546
@FXML
4647
private Button save;
4748

49+
@FXML
50+
private Button browse;
51+
52+
@FXML
53+
private Label pathToBashText;
54+
4855
@FXML
4956
private Label done;
5057

5158
@Override
5259
public void initialize(FxmlStageHolder fxmlStageHolder) {
5360
super.initialize(fxmlStageHolder);
5461
super.setClosingOnEscapePressing(fxmlStageHolder);
55-
final String pathToGitBashExeStr = AppConfig.getInstance().getPathToGitBashExe();
56-
if (pathToGitBashExeStr != null && !pathToGitBashExeStr.isEmpty()) {
57-
pathToBashExe.setText(pathToGitBashExeStr);
62+
if (OsRecogniser.isCurrentOsUnixLike()) {
63+
pathToBashExe.disableProperty().set(true);
64+
browse.setDisable(true);
65+
pathToBashText.setDisable(true);
66+
} else {
67+
final String pathToGitBashExeStr = AppConfig.getInstance().getPathToGitBashExe();
68+
if (pathToGitBashExeStr != null && !pathToGitBashExeStr.isEmpty()) {
69+
pathToBashExe.setText(pathToGitBashExeStr);
70+
}
5871
}
5972
save.requestFocus();
6073
if (done != null) {

src/main/java/com/github/introfog/gitwave/controller/main/MenuController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.introfog.gitwave.controller.SupportController;
44
import com.github.introfog.gitwave.model.AppConfig;
55
import com.github.introfog.gitwave.model.DialogFactory;
6+
import com.github.introfog.gitwave.model.OsRecogniser;
67
import com.github.introfog.gitwave.model.StageFactory;
78
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
89
import com.github.introfog.gitwave.model.UpdateChecker;
@@ -31,6 +32,9 @@ public MenuController(FxmlStageHolder fxmlStageHolder, Menu menu, MenuItem updat
3132

3233
@Override
3334
public boolean isValid() {
35+
if (OsRecogniser.isCurrentOsUnixLike()) {
36+
return true;
37+
}
3438
final String pathToGitBashExe = AppConfig.getInstance().getPathToGitBashExe();
3539
if (pathToGitBashExe == null || pathToGitBashExe.isEmpty()) {
3640
DialogFactory.createErrorAlert("GitBash path hasn't been specified", "Specify path to GitBash in Menu->Settings.");

src/main/java/com/github/introfog/gitwave/model/CommandExecutor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ public static void executeCommand(List<File> repositoriesToRunCommand, Execution
5252
return;
5353
}
5454
controller.writeDirectory(runnableCommand.path);
55-
Process powerShellProcess = Runtime.getRuntime().exec(runnableCommand.params);
55+
Process process = Runtime.getRuntime().exec(runnableCommand.params);
5656

5757
String line;
58-
BufferedReader stdout = new BufferedReader(new InputStreamReader(powerShellProcess.getInputStream()));
58+
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
5959

6060
while ((line = stdout.readLine()) != null) {
6161
controller.writeStandardOutput(line);
6262
}
6363
stdout.close();
6464

65-
BufferedReader stderr = new BufferedReader(new InputStreamReader(powerShellProcess.getErrorStream()));
65+
BufferedReader stderr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
6666
while ((line = stderr.readLine()) != null) {
6767
controller.writeErrorOutput(line);
6868
}
@@ -86,7 +86,11 @@ private static List<RunnableCommand> createRunnableCommands(List<File> repositor
8686

8787
private static String[] constructCmdCommand(String gitRepoPath, String command) {
8888
List<String> cmdCommand = new ArrayList<>();
89-
cmdCommand.add(AppConfig.getInstance().getPathToGitBashExe().replace("\\", "/"));
89+
if (OsRecogniser.isCurrentOsUnixLike()) {
90+
cmdCommand.add("bash");
91+
} else {
92+
cmdCommand.add(AppConfig.getInstance().getPathToGitBashExe().replace("\\", "/"));
93+
}
9094
cmdCommand.add("-c");
9195
cmdCommand.add("cd '" + gitRepoPath + "' && " + command);
9296
return cmdCommand.toArray(new String[]{});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2023-2024 Dmitry Chubrick
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.introfog.gitwave.model;
18+
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
public final class OsRecogniser {
23+
private static final Logger LOGGER = LoggerFactory.getLogger(OsRecogniser.class);
24+
25+
private static CurrentOs currentOs;
26+
27+
private OsRecogniser() {
28+
// Do nothing
29+
}
30+
31+
public static boolean isCurrentOsUnixLike() {
32+
return getCurrentOs() == CurrentOs.MACOS || getCurrentOs() == CurrentOs.LINUX;
33+
}
34+
35+
public static CurrentOs getCurrentOs() {
36+
if (currentOs == null) {
37+
String os = System.getProperty("os.name").toLowerCase();
38+
if (os.contains("win")) {
39+
currentOs = CurrentOs.WINDOWS;
40+
} else if (os.contains("mac")) {
41+
currentOs = CurrentOs.MACOS;
42+
} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {
43+
currentOs = CurrentOs.LINUX;
44+
} else {
45+
currentOs = CurrentOs.UNRECOGNISED;
46+
}
47+
LOGGER.info("System.getProperty(\"os.name\")={}. Recognised OS: {}", os, currentOs);
48+
}
49+
return currentOs;
50+
}
51+
52+
public enum CurrentOs {
53+
WINDOWS,
54+
MACOS,
55+
LINUX,
56+
UNRECOGNISED
57+
}
58+
}

src/main/resources/com/github/introfog/gitwave/view/settings.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<children>
2626
<AnchorPane prefHeight="200.0" prefWidth="200.0">
2727
<children>
28-
<Label prefHeight="17.0" prefWidth="430.0" text="Path to bash.exe on your PC (usually &quot;PATH_TO_GIT/bin/bash.exe&quot;)." AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
29-
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
28+
<Label fx:id="pathToBashText" prefHeight="17.0" prefWidth="430.0" text="Path to bash.exe on your PC (usually &quot;PATH_TO_GIT/bin/bash.exe&quot;)." AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
29+
<Button fx:id="browse" mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
3030
<font>
3131
<Font name="Verdana" size="12.0" />
3232
</font>

tools/GitWave.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
nohup ./javaImage/bin/GitWave > /dev/null 2>&1 &

0 commit comments

Comments
 (0)