Skip to content

Commit

Permalink
build: force code style
Browse files Browse the repository at this point in the history
  • Loading branch information
jagodevreede committed Jul 10, 2024
1 parent cb18a21 commit 6e43753
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 88 deletions.
380 changes: 380 additions & 0 deletions code-style/eclipse-formatter-config.xml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<code-style.configFile>../code-style/eclipse-formatter-config.xml</code-style.configFile>

<junit.version>5.10.3</junit.version>
<assertj.version>3.26.0</assertj.version>
Expand Down Expand Up @@ -68,6 +69,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<configuration>
<configFile>${code-style.configFile}</configFile>
</configuration>
<executions>
<execution>
<id>format-code</id>
<phase>validate</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public List<Candidate> getCandidates() throws IOException, InterruptedException
//return CandidateListParser.parse(response);
// Use hard coded list for now as we don't support everything yet
return List.of(
new Candidate("java", "Java", "Java Development Kit"),
new Candidate("maven", "Maven", "Maven")
new Candidate("java", "Java", "Java Development Kit"), new Candidate("maven", "Maven", "Maven")
);
}

Expand All @@ -104,11 +103,7 @@ public List<CandidateVersion> getVersions(String candidate) throws IOException,
var available = localAvailable.remove(identifier);
if (matcher.matches()) {
var dist = matcher.group(2);
var name = vendors.stream()
.filter(v -> Objects.equals(v.dist(), dist))
.findFirst()
.map(Vendor::vendor)
.orElse("Unclassified");
var name = vendors.stream().filter(v -> Objects.equals(v.dist(), dist)).findFirst().map(Vendor::vendor).orElse("Unclassified");
result.add(new CandidateVersion(name, matcher.group(1), dist, identifier, true, available));
} else {
result.add(new CandidateVersion("Unclassified", "", "none", identifier, true, available));
Expand All @@ -119,11 +114,7 @@ public List<CandidateVersion> getVersions(String candidate) throws IOException,
Matcher matcher = IDENTIFIER_PATTERN.matcher(identifier);
if (matcher.matches()) {
var dist = matcher.group(2);
var name = vendors.stream()
.filter(v -> Objects.equals(v.dist(), dist))
.findFirst()
.map(Vendor::vendor)
.orElse("Unclassified");
var name = vendors.stream().filter(v -> Objects.equals(v.dist(), dist)).findFirst().map(Vendor::vendor).orElse("Unclassified");
result.add(new CandidateVersion(name, matcher.group(1), dist, identifier, false, true));
} else {
result.add(new CandidateVersion("Unclassified", "", "none", identifier, false, true));
Expand Down Expand Up @@ -172,19 +163,15 @@ public List<String> getLocalInstalledVersions(String candidate) {
if (!candidatesFolder.exists()) {
return List.of();
}
return List.of(Objects.requireNonNull(candidatesFolder.list((dir, name) ->
new File(dir, name).isDirectory() && !"current".equals(name))));
return List.of(Objects.requireNonNull(candidatesFolder.list((dir, name) -> new File(dir, name).isDirectory() && !"current".equals(name))));
}

private List<String> getLocalAvailableVersions(String candidate) {
var archiveFolder = new File(baseFolder + separator + "archives");
if (!archiveFolder.exists()) {
return List.of();
}
return Stream.of(Objects.requireNonNull(archiveFolder.list((dir, name) ->
new File(dir, name).isFile() && name.startsWith(candidate) && name.endsWith(".zip"))))
.map(name -> name.substring(candidate.length() + 1, name.length() - 4))
.toList();
return Stream.of(Objects.requireNonNull(archiveFolder.list((dir, name) -> new File(dir, name).isFile() && name.startsWith(candidate) && name.endsWith(".zip")))).map(name -> name.substring(candidate.length() + 1, name.length() - 4)).toList();
}

public String getCurrentCandidateFromPath(String candidate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static SdkManUiPreferences load() throws IOException {
return uiPreferences;
}

public static SdkManUiPreferences getInstance() {
public static SdkManUiPreferences getInstance() {
if (INSTACE == null) {
try {
INSTACE = load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import java.io.IOException;

public enum ArchiveType {
ZIP,
TAR_GZ,
TAR;
ZIP, TAR_GZ, TAR;

public ArchiveInputStream<?> getInputStream(File file) throws IOException {
return switch (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,15 @@ public static File findRoot(File folderToSearchIn, String folderName) {
return null;
}

public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation)
throws IOException {
Files.walk(Paths.get(sourceDirectoryLocation))
.forEach(source -> {
Path destination = Paths.get(destinationDirectoryLocation, source.toString()
.substring(sourceDirectoryLocation.length()));
try {
Files.copy(source, destination);
} catch (IOException e) {
e.printStackTrace();
}
});
public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException {
Files.walk(Paths.get(sourceDirectoryLocation)).forEach(source -> {
Path destination = Paths.get(destinationDirectoryLocation, source.toString().substring(sourceDirectoryLocation.length()));
try {
Files.copy(source, destination);
} catch (IOException e) {
e.printStackTrace();
}
});
}

public static void makeAccessible(final File f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public String get(String url, boolean offline, Map<String, String> headers) thro
throw new IllegalStateException(message);
}
try {
var httpBuilder = HttpRequest.newBuilder()
.uri(java.net.URI.create(url));
var httpBuilder = HttpRequest.newBuilder().uri(java.net.URI.create(url));
headers.forEach((k, v) -> httpBuilder.setHeader(k, v));
var getRequest = httpBuilder.build();
var response = httpClient.send(getRequest, java.net.http.HttpResponse.BodyHandlers.ofString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ public void download() {
connection.connect();

if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IllegalStateException("Server returned HTTP " + connection.getResponseCode()
+ " " + connection.getResponseMessage());
throw new IllegalStateException("Server returned HTTP " + connection.getResponseCode() + " " + connection.getResponseMessage());
}

// this will be useful to display download percentage
// might be -1: server did not report the length
int fileLength = connection.getContentLength();
try (InputStream input = connection.getInputStream();
OutputStream output = new FileOutputStream(tempFile)) {
try (InputStream input = connection.getInputStream(); OutputStream output = new FileOutputStream(tempFile)) {

byte[] data = new byte[4096];
long total = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class CandidateListParserTest {
void parse() throws Exception {
String resource = loadFileFromResource("api_examples/candidates/list/out.txt");
var candidates = CandidateListParser.parse(resource);
assertThat(candidates)
.isNotNull()
.hasSize(72);
assertThat(candidates).isNotNull().hasSize(72);

assertThat(candidates.get(0).id()).isEqualTo("activemq");
assertThat(candidates.get(0).name()).isEqualTo("Apache ActiveMQ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class VersionListParserTest {
void parseJava_small() throws Exception {
String resource = loadFileFromResource("api_examples/candidates/java/linux/versions/list/small.txt");
var javaVersions = VersionListParser.parse(resource);
assertThat(javaVersions)
.isNotNull()
.hasSize(5);
assertThat(javaVersions).isNotNull().hasSize(5);

assertThat(javaVersions.get(0).vendor()).isEqualTo("Corretto");
assertThat(javaVersions.get(0).version()).isEqualTo("22");
Expand All @@ -25,17 +23,13 @@ void parseJava_small() throws Exception {
void parseJava() throws Exception {
String resource = loadFileFromResource("api_examples/candidates/java/linux/versions/list/out.txt");
var javaVersions = VersionListParser.parse(resource);
assertThat(javaVersions)
.isNotNull()
.hasSize(165);
assertThat(javaVersions).isNotNull().hasSize(165);
}

@Test
void parseOther() throws Exception {
String resource = loadFileFromResource("api_examples/candidates/maven/versions/list/out.txt");
var javaVersions = VersionListParser.parse(resource);
assertThat(javaVersions)
.isNotNull()
.hasSize(42);
assertThat(javaVersions).isNotNull().hasSize(42);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ private ApplicationVersion() {
// hidden constructor as it is a static instance.

try {
InputStream resourceAsStream = ApplicationVersion.class.getClassLoader()
.getResourceAsStream("version.txt");
InputStream resourceAsStream = ApplicationVersion.class.getClassLoader().getResourceAsStream("version.txt");
version = new String(resourceAsStream.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
version = "unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ static String testExecutable(String command, Stage stage) {
logger.debug("Testing for {}", command);
if (!ProcessStarter.testIfAvailable(command)) {
logger.info("{} is not on path", command);
ServiceRegistry.INSTANCE.getPopupView().showInformation(command + " is not available,\n" +
"Please install it or in the next dialog point to where it is.");
ServiceRegistry.INSTANCE.getPopupView().showInformation(command + " is not available,\n" + "Please install it or in the next dialog point to where it is.");
FileChooser fileChooser = new FileChooser();
if (isWindows()) {
fileChooser.setInitialDirectory(new File("./"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ private static void install() {
boolean configured = SERVICE_REGISTRY.getApi().configureEnvironmentPath();
try {
Files.copy(currentExecutable.toPath(), new File(installFolder, currentExecutable.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(ApplicationVersion.class.getClassLoader().getResourceAsStream("sdkui.cmd"), new File(installFolder, "sdkui.cmd").toPath(),
StandardCopyOption.REPLACE_EXISTING);
Files.copy(ApplicationVersion.class.getClassLoader().getResourceAsStream("version.txt"), new File(installFolder, "version.txt").toPath(),
StandardCopyOption.REPLACE_EXISTING);
Files.copy(ApplicationVersion.class.getClassLoader().getResourceAsStream("sdkui.cmd"), new File(installFolder, "sdkui.cmd").toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(ApplicationVersion.class.getClassLoader().getResourceAsStream("version.txt"), new File(installFolder, "version.txt").toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,18 @@ public void loadData(Runnable onLoaded) {
String pathVersionInUse = api.getCurrentCandidateFromPath(selectedCandidate);
setGlobalVersionLabel(globalVersionInUse);
setPathVersionLabel(pathVersionInUse);
List<CandidateVersion> updatedVersions = api.getVersions(selectedCandidate).stream()
.filter(j -> !showInstalledOnly.isSelected() || j.installed())
.filter(j -> !showAvailableOnly.isSelected() || j.available())
.filter(j -> {
if (searchField == null || searchField.getText() == null || searchField.getText().isBlank()) {
return true;
} else {
final boolean vendorMatchesSearch = Pattern.compile(Pattern.quote(searchField.getText()), Pattern.CASE_INSENSITIVE).matcher(j.vendor()).find();
final boolean identifierMatchesSearch = Pattern.compile(Pattern.quote(searchField.getText()), Pattern.CASE_INSENSITIVE).matcher(j.identifier()).find();
return vendorMatchesSearch || identifierMatchesSearch;
}
})
.toList();
List<CandidateVersion> updatedVersions = api.getVersions(selectedCandidate).stream().filter(j -> !showInstalledOnly.isSelected() || j.installed()).filter(j -> !showAvailableOnly.isSelected() || j.available()).filter(j -> {
if (searchField == null || searchField.getText() == null || searchField.getText().isBlank()) {
return true;
} else {
final boolean vendorMatchesSearch = Pattern.compile(Pattern.quote(searchField.getText()), Pattern.CASE_INSENSITIVE).matcher(j.vendor()).find();
final boolean identifierMatchesSearch = Pattern.compile(Pattern.quote(searchField.getText()), Pattern.CASE_INSENSITIVE).matcher(j.identifier()).find();
return vendorMatchesSearch || identifierMatchesSearch;
}
}).toList();
Platform.runLater(() -> {
if (tableData == null || tableData.size() != updatedVersions.size()) {
tableData = FXCollections.observableArrayList(
updatedVersions.stream()
.map(j -> new VersionView(j, globalVersionInUse, pathVersionInUse, thiz)).toList()
);
tableData = FXCollections.observableArrayList(updatedVersions.stream().map(j -> new VersionView(j, globalVersionInUse, pathVersionInUse, thiz)).toList());
table.setItems(tableData);
} else {
tableData.forEach(oldData -> {
Expand Down Expand Up @@ -201,9 +194,7 @@ private void setGlobalVersionLabel(String globalVersionInUse) {

private static TableColumn<VersionView, String> getTableColumn(String title, String property) {
TableColumn<VersionView, String> vendorCol = new TableColumn<>(title);
vendorCol.setCellValueFactory(
new PropertyValueFactory<>(property)
);
vendorCol.setCellValueFactory(new PropertyValueFactory<>(property));
return vendorCol;
}

Expand Down Expand Up @@ -242,10 +233,9 @@ private void switchCandidate(String candidate) {
private void checkIfEnvironmentIsConfigured(String candidate) {
// Only on windows, check if the environment is configured
if (OsHelper.isWindows() && hasInstalledVersion() && !api.hasCandidateEnvironmentPathConfigured(candidate)) {
Platform.runLater(() -> popupView.showConfirmation("Configure environment for " + candidate,
candidate + " is not in the environment (path variable) yet, do you want to add it?", () -> {
api.configureWindowsEnvironment(candidate);
}));
Platform.runLater(() -> popupView.showConfirmation("Configure environment for " + candidate, candidate + " is not in the environment (path variable) yet, do you want to add it?", () -> {
api.configureWindowsEnvironment(candidate);
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void run(Task<?> task) {
t.setUncaughtExceptionHandler(new GlobalExceptionHandler());
t.start();
}

public static void run(Runnable task) {
run(new Task<Void>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class GitHubRelease {
private final CachedHttpClient cachedHttpClient;
private final ServiceRegistry serviceRegistry = ServiceRegistry.INSTANCE;
private final static Map<String, String> HEADERS = Map.of(
"Accept", "application/vnd.github+json",
"X-GitHub-Api-Version", "2022-11-28"
"Accept", "application/vnd.github+json", "X-GitHub-Api-Version", "2022-11-28"
);

public GitHubRelease(String cacheFolder, HttpClient httpClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ public String getIdentifier() {
return identifier.get();
}

public HBox getInstalled() { return installed; }
public HBox getInstalled() {
return installed;
}

public boolean isInstalled() {
return isInstalled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void injectMocks() {
subject = new GitHubRelease(cachedHttpClient);
}


@Test
void getLatestRelease() throws IOException, InterruptedException {
String httpResponse = loadFileFromResource("github_api_examples/releases/latest.json");
Expand Down

0 comments on commit 6e43753

Please sign in to comment.