Skip to content

Commit

Permalink
Merge pull request #47 from cleydyr/musl-autodetection
Browse files Browse the repository at this point in the history
Add Musl autodetection
  • Loading branch information
cleydyr authored Sep 22, 2024
2 parents cd00bf4 + 28457eb commit e59610f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- New feature to autodetect Linux Musl systems and use the Musl version of the
binary if detected

### Removed

- Cascade-remove support for Windows 7 and 8 as per https://github.com/dart-lang/sdk/issues/54509
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ This parameter represents the Dart Sass operating system that should be used to
**Type**: String<br>
**Required**: No

> [!WARNING]
> When compiling on alpine derived images, setting `os` to `linux-musl` is required as it cannot be autodetected.
`<version>`

This parameter represents the Dart Sass version that should be used to compile Sass files. If left unset, the version available at https://github.com/sass/dart-sass/releases/latest will be used.<br>
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>io.github.cleydyr</groupId>
<artifactId>dart-sass-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.3.1-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<name>dart-sass-maven-plugin Maven Mojo</name>
<description>A Maven plugin that allows to compile SASS using Dart Sass</description>
<developers>
Expand All @@ -29,8 +29,8 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spotless.version>2.43.0</spotless.version>
<maven.version>3.9.6</maven.version>
<maven.plugin.version>3.11.0</maven.plugin.version>
<maven.version>3.9.8</maven.version>
<maven.plugin.version>3.12.0</maven.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
Expand Down Expand Up @@ -67,19 +67,19 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5-fluent</artifactId>
<version>5.3.1</version>
<version>5.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -89,7 +89,7 @@
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.321</version>
<version>1.326</version>
</dependency>
</dependencies>
<reporting>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/github/cleydyr/dart/system/OSDetector.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.cleydyr.dart.system;

import com.github.cleydyr.dart.system.exception.OSDetectionException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -59,6 +62,10 @@ private OSDetector() {
DETECTED_OS = OS_WINDOWS;

IS_WINDOWS = true;
} else if (isLinuxMusl()) {
DETECTED_OS = OS_LINUX_WITH_MUSL;

IS_WINDOWS = false;
} else {
DETECTED_OS = OS_LINUX;

Expand Down Expand Up @@ -101,4 +108,27 @@ public static boolean isAcceptedOSName(String osName) {
public static boolean isAcceptedArchitecture(String architecture) {
return ACCEPTED_ARCHITECTURES.stream().anyMatch(architecture::equals);
}

public static boolean isLinuxMusl() {
try {
ProcessBuilder processBuilder = new ProcessBuilder("ldd", "--version");

Process process = processBuilder.start();

InputStream inputStream = process.getErrorStream();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
boolean hasMusl = reader.lines().anyMatch(line -> line.contains("musl"));

process.waitFor();

return hasMusl;
}
} catch (Exception e) {
// TODO: log warning
e.printStackTrace();
}

return false;
}
}
7 changes: 3 additions & 4 deletions src/test/resources/musl/test-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.cleydyr</groupId>
<artifactId>test-project</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>

<name>test-project</name>
<description>A simple test-project.</description>
Expand All @@ -21,12 +21,11 @@
<plugin>
<groupId>io.github.cleydyr</groupId>
<artifactId>dart-sass-maven-plugin</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<configuration>
<outputFolder>${project.build.directory}/static/styles</outputFolder>
<style>COMPRESSED</style>
<version>1.71.1</version>
<os>linux-musl</os>
<version>1.79.3</version>
</configuration>
<executions>
<execution>
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/test-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.cleydyr</groupId>
<artifactId>test-project</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>

<name>test-project</name>
<description>A simple test-project.</description>
Expand All @@ -21,11 +21,11 @@
<plugin>
<groupId>io.github.cleydyr</groupId>
<artifactId>dart-sass-maven-plugin</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<configuration>
<outputFolder>${project.build.directory}/static/styles</outputFolder>
<style>COMPRESSED</style>
<version>1.71.1</version>
<version>1.79.3</version>
</configuration>
<executions>
<execution>
Expand Down

0 comments on commit e59610f

Please sign in to comment.