Skip to content

Commit

Permalink
Generate an executable JAR as an extra release file
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisJehan committed Sep 6, 2024
1 parent 334e2c4 commit c820b45
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 33 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

## 1.7.0 (unreleased)

### New features
- [[#5](https://github.com/AlexisJehan/MvnCheck/issues/5)] Generate an executable JAR as an extra release file (thanks
to [TobseF](https://github.com/TobseF))

### Bug fixes
- [[#3](https://github.com/AlexisJehan/MvnCheck/issues/3)] Fix parsing errors related to the BOM character of the UTF-8 with BOM encoding (thanks to [TobseF](https://github.com/TobseF))
- [[#3](https://github.com/AlexisJehan/MvnCheck/issues/3)] Fix parsing errors related to the BOM character of the UTF-8
with BOM encoding (thanks to [TobseF](https://github.com/TobseF))

### Improvements
- Improve the _Maven Artifact Resolver_ usage by migrating from `Eclipse Sisu` to `Supplier`

### Notes
- Add the `maven-resolver-supplier` dependency
- Update the `maven-core` dependency to `3.9.9`
- Update `maven-resolver-connector-basic` and `maven-resolver-transport-http` dependencies to `1.9.22`
- Update the `gradle-tooling-api` dependency to `8.10`
- Update the `github-api` dependency to `1.324`
- Update the `commons-cli` dependency to `1.9.0`
Expand All @@ -18,6 +26,7 @@
- Update `maven-surefire-plugin` and `maven-failsafe-plugin` plugins to `3.5.0`
- Update the `maven-javadoc-plugin` plugin to `3.10.0`
- Update the `maven-gpg-plugin` plugin to `3.2.5`
- Remove `maven-resolver-connector-basic` and `maven-resolver-transport-http` dependencies

## [1.6.2](https://github.com/AlexisJehan/MvnCheck/releases/tag/v1.6.2) (2024-07-16)

Expand Down Expand Up @@ -207,7 +216,7 @@

### Improvements
- Improve resolving the _Maven_ version
- Improve _Maven_ dependency injection by migrating from `ServiceLocator` to `Eclipse Sisu`
- Improve the _Maven Artifact Resolver_ usage by migrating from `ServiceLocator` to `Eclipse Sisu`
- Improve exceptions output
- Improve some log levels

Expand Down
45 changes: 30 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<artifactId>maven-resolver-supplier</artifactId>
<version>1.9.22</version> <!-- Based on "org.apache.maven:maven-core:3.9.9" -->
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>1.9.22</version> <!-- Based on "org.apache.maven:maven-core:3.9.9" -->
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gradle</groupId>
Expand Down Expand Up @@ -419,19 +412,41 @@
<version>3.7.1</version>
<executions>
<execution>
<id>assembly-single</id>
<id>assembly-single-bin</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
</descriptors>
<outputTimestamp>${maven.build.timestamp}</outputTimestamp>
</configuration>
</execution>
<execution>
<id>assembly-single-bin-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>com.github.alexisjehan.mvncheck.Application</mainClass>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
<descriptors>
<descriptor>src/main/assembly/bin-jar.xml</descriptor>
</descriptors>
<outputTimestamp>${maven.build.timestamp}</outputTimestamp>
</configuration>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
</descriptors>
<outputTimestamp>${maven.build.timestamp}</outputTimestamp>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
29 changes: 29 additions & 0 deletions src/main/assembly/bin-jar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 https://maven.apache.org/xsd/assembly-2.2.0.xsd">
<id>bin</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>provided</scope>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<includes>
<include>LICENSE.txt</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@
import java.io.IOException;
import java.io.OutputStream;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -61,11 +64,23 @@
*/
public final class GradleBuildResolver implements BuildResolver {

/**
* <p>Prefix of the initialisation file name.</p>
* @since 1.7.0
*/
private static final String INIT_FILE_NAME_PREFIX = "init";

/**
* <p>Suffix of the initialisation file name.</p>
* @since 1.7.0
*/
private static final String INIT_FILE_NAME_SUFFIX = ".gradle";

/**
* <p>Initialisation file name.</p>
* @since 1.0.0
*/
private static final String INIT_FILE_NAME = "init.gradle";
private static final String INIT_FILE_NAME = INIT_FILE_NAME_PREFIX + INIT_FILE_NAME_SUFFIX;

/**
* <p>{@link Set} of file types.</p>
Expand Down Expand Up @@ -126,11 +141,21 @@ private Build resolve(final BuildFile file, final OutputStream outputStream) thr
connector.useInstallation(installation.toFile());
});
try (var connection = connector.connect()) {
connection.newBuild()
.forTasks("repositories", "dependencies")
.withArguments("--init-script=" + getClass().getClassLoader().getResource(INIT_FILE_NAME))
.setStandardOutput(outputStream)
.run();
final var initTempFile = Files.createTempFile(INIT_FILE_NAME_PREFIX, INIT_FILE_NAME_SUFFIX);
try {
Files.copy(
Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(INIT_FILE_NAME)),
initTempFile,
StandardCopyOption.REPLACE_EXISTING
);
connection.newBuild()
.forTasks("repositories", "dependencies")
.withArguments("--init-script=" + initTempFile)
.setStandardOutput(outputStream)
.run();
} finally {
Files.delete(initTempFile);
}
} catch (final GradleConnectionException e) {
throw new BuildResolveException(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import com.github.alexisjehan.javanilla.lang.Strings;
import com.github.alexisjehan.javanilla.misc.quality.Ensure;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
Expand All @@ -42,6 +40,9 @@
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider;
import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager;
import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer;
import org.eclipse.aether.repository.AuthenticationSelector;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.MirrorSelector;
Expand All @@ -50,14 +51,13 @@
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.spi.locator.ServiceLocator;
import org.eclipse.aether.supplier.RepositorySystemSupplier;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.eclipse.aether.util.repository.ConservativeAuthenticationSelector;
import org.eclipse.aether.util.repository.ConservativeProxySelector;
import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
import org.eclipse.aether.util.repository.DefaultMirrorSelector;
import org.eclipse.aether.util.repository.DefaultProxySelector;
import org.eclipse.sisu.launch.Main;
import org.eclipse.sisu.space.BeanScanning;
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;

Expand Down Expand Up @@ -121,10 +121,10 @@ public final class MavenUtils {
private static final Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass());

/**
* <p>Dependency injector.</p>
* @since 1.1.0
* <p>Repository system supplier.</p>
* @since 1.7.0
*/
private static final Injector injector = Guice.createInjector(Main.wire(BeanScanning.INDEX));
private static final RepositorySystemSupplier repositorySystemSupplier = new RepositorySystemSupplier();

/**
* <p>Constructor.</p>
Expand Down Expand Up @@ -247,7 +247,7 @@ public static RepositorySystem makeRepositorySystem(final ServiceLocator service
* @since 1.1.0
*/
public static RepositorySystem makeRepositorySystem() {
return injector.getInstance(RepositorySystem.class);
return repositorySystemSupplier.get();
}

/**
Expand All @@ -270,7 +270,10 @@ public static RemoteRepositoryManager makeRemoteRepositoryManager(final ServiceL
* @since 1.1.0
*/
public static RemoteRepositoryManager makeRemoteRepositoryManager() {
return injector.getInstance(RemoteRepositoryManager.class);
return new DefaultRemoteRepositoryManager(
new DefaultUpdatePolicyAnalyzer(),
new DefaultChecksumPolicyProvider()
);
}

/**
Expand Down

0 comments on commit c820b45

Please sign in to comment.