Skip to content

Commit

Permalink
Merge branch '1.3'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
v1nc3n4 committed Dec 7, 2019
2 parents 5f6adfe + bcd9074 commit 2c2f2c0
Show file tree
Hide file tree
Showing 31 changed files with 292 additions and 162 deletions.
33 changes: 28 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,41 @@ matrix:
- sonar-scanner

- os: linux
dist: xenial
jdk: oraclejdk8
dist: bionic
jdk: openjdk11

- os: osx
osx_image: xcode9.4
jdk: oraclejdk11

- os: windows
# Java is not yet supported on Windows, so the build would block.
# You do not need any setup from Travis, use a plain bash build
language: bash
env:
# This is a convenience variable for shortening download commands
- GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
# If you use Windows, you may want to disable Windows Defender. It slows down the builds
# dramatically, also during cache setup. From a Tanzinul Islam's idea: http://bit.ly/348VPYS,
# This work around disables it before caching
- NO_WIN_DEFENDER=$(curl "${GRAVIS}.disable-windows-defender.sh" --output .no-defender.sh && source .no-defender.sh)
# List any JDK you want to build your software with.
# You can see the list of supported environments by installing Jabba and using ls-remote:
# https://github.com/shyiko/jabba#usage
- JDK="[email protected]"
before_install:
# Download the script, and download, install, configue the JDK, and export the configuration to the current shell
- curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh
- source ~/.install-jdk-travis.sh
before_cache:
- curl "${GRAVIS}.clean_gradle_cache.sh" --output ~/.clean_gradle_cache.sh
- bash ~/.clean_gradle_cache.sh

language: java

git:
depth: 3

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand All @@ -38,8 +64,5 @@ cache:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

git:
depth: 3

script:
- ./gradlew check --scan
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ gradlew pluginUnderTestMetadata
The project relies on [Travis CI Open Source][travis] to integrate continuously every change, pull request, in the
repository. The configuration actually allows to build and test the plugin on the environments below:

- Linux Ubuntu Xenial Xerus 16.04.6 LTS / OpenJDK 1.8.0_191 64 bits
- Linux Ubuntu Xenial Xerus 16.04.6 LTS / OracleJDK 1.8.0_151 64 bits
- Mac OS X 10.13 / OracleJDK 11.0.2 LTS 64 bits
- Linux Ubuntu Xenial 16.04.6 LTS / OpenJDK 1.8.0_222 64 bits
- Linux Ubuntu Bionic 18.04.3 LTS / OpenJDK 11.0.2 64 bits
- Mac OS X 10.13.3 / OpenJDK 11.0.2 64 bits
- Windows Server 2016 version 1803 / AdoptOpenJDK OpenJ9 1.8.0-232 64 bits

Ubuntu Xenial is the reference environment, used to analyze the source code with SonarCloud. By now, the plugin has been
developed on Windows 10 Home with OracleJDK 1.8.0_202 64 bits and [JetBrains IntelliJ IDEA][intellij].
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Frontend Gradle plugin

[![Latest release 1.2.1](https://img.shields.io/badge/Latest%20release-1.2.1-blue.svg)](https://github.com/Siouan/frontend-gradle-plugin/releases/tag/v1.2.1)
[![Latest release 1.3.0](https://img.shields.io/badge/Latest%20release-1.3.0-blue.svg)](https://github.com/Siouan/frontend-gradle-plugin/releases/tag/v1.3.0)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)

[![Build status](https://travis-ci.com/Siouan/frontend-gradle-plugin.svg?branch=master)](https://travis-ci.com/Siouan/frontend-gradle-plugin)
Expand Down Expand Up @@ -65,7 +65,7 @@ This is the modern and recommended approach.
```groovy
// build.gradle
plugins {
id 'org.siouan.frontend' version '1.2.1'
id 'org.siouan.frontend' version '1.3.0'
}
```

Expand All @@ -80,7 +80,7 @@ buildscript {
url 'https://plugins.gradle.org/m2/'
}
dependencies {
classpath 'org.siouan:frontend-gradle-plugin:1.2.1'
classpath 'org.siouan:frontend-gradle-plugin:1.3.0'
}
}
Expand All @@ -99,7 +99,7 @@ frontend {
// NODE SETTINGS
// Node version, used to build the URL to download the corresponding distribution, if the 'nodeDistributionUrl'
// property is not set.
nodeVersion = '10.16.0'
nodeVersion = '12.13.1'
// [OPTIONAL] Sets this property to force the download from a custom website. By default, this property is
// 'null', and the plugin attempts to download the distribution compatible with the current platform from
Expand All @@ -119,7 +119,7 @@ frontend {
// [OPTIONAL] Yarn version, used to build the URL to download the corresponding distribution, if the
// 'yarnDistributionUrl' property is not set. This property is mandatory when the 'yarnEnabled' property is
// true.
yarnVersion = '1.16.0'
yarnVersion = '1.19.2'
// [OPTIONAL] Sets this property to force the download from a custom website. By default, this property is
// 'null', and the plugin attempts to download the distribution compatible with the current platform from
Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-gradle-plugin'
id 'maven-publish'
id 'jacoco'
id 'com.gradle.build-scan' version '2.3'
id 'com.gradle.build-scan' version '3.1'
id 'com.gradle.plugin-publish' version '0.10.1'
}

Expand Down Expand Up @@ -33,17 +33,17 @@ jacocoTestReport {

dependencies {
implementation gradleApi()
implementation 'org.apache.commons:commons-compress:1.18'
implementation 'org.apache.commons:commons-compress:1.19'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
testImplementation 'org.mockito:mockito-core:2.28.2'
testImplementation 'org.mockito:mockito-junit-jupiter:2.28.2'
testImplementation 'org.assertj:assertj-core:3.12.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testImplementation 'org.mockito:mockito-core:3.2.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.2.0'
testImplementation 'org.assertj:assertj-core:3.14.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
}

group 'org.siouan'
version '1.2.1'
version '1.3.0'
description 'Integrate your frontend Node/NPM/Yarn build into Gradle.'

sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.projectKey=Siouan_frontend-gradle-plugin
sonar.projectName=frontend-gradle-plugin
sonar.projectVersion=1.2.1
sonar.projectVersion=1.3.0

sonar.links.homepage=https://github.com/Siouan/frontend-gradle-plugin
sonar.links.ci=https://travis-ci.com/Siouan/frontend-gradle-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class FrontendGradlePlugin implements Plugin<Project> {
*/
public static final String CLEAN_TASK_NAME = "cleanFrontend";

/**
* Name of the NPM/Yarn command that shall be executed to install frontend dependencies.
*/
private static final String DEFAULT_INSTALL_SCRIPT = "install";

/**
* Name of the task that installs a Node distribution.
*/
Expand Down Expand Up @@ -95,6 +100,7 @@ public void apply(final Project project) {
extension.getNodeInstallDirectory().convention(new File(project.getProjectDir(), DEFAULT_NODE_INSTALL_DIRNAME));
extension.getYarnEnabled().convention(false);
extension.getYarnInstallDirectory().convention(new File(project.getProjectDir(), DEFAULT_YARN_INSTALL_DIRNAME));
extension.getInstallScript().convention(DEFAULT_INSTALL_SCRIPT);

final TaskContainer projectTasks = project.getTasks();
projectTasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ public DistributionInstaller(final DistributionInstallerSettings settings) {
*/
public void install() throws DistributionInstallerException {
try {
checkInstallDirectory();
deleteInstallDirectory();

// Resolve the URL to download the distribution
final URL distributionUrl = settings.getUrlResolver().resolve();

// Download the distribution
final String distributionUrlAsString = distributionUrl.toString();
logLifecycle("Downloading distribution at '" + distributionUrlAsString + "'");
final Path distributionFile = settings.getInstallDirectory()
final Path distributionFile = settings
.getTemporaryDirectory()
.resolve(distributionUrlAsString.substring(distributionUrlAsString.lastIndexOf('/') + 1));
settings.getDownloader().download(distributionUrl, distributionFile);

Expand All @@ -61,13 +62,14 @@ public void install() throws DistributionInstallerException {
validator.get().validate(distributionUrl, distributionFile);
}


// Explodes the archive
logLifecycle("Exploding distribution into '" + distributionFile.getParent() + "'");
final ExplodeSettings explodeSettings = new ExplodeSettings(distributionFile, distributionFile.getParent(),
final Path explodeTargetDirectory = Files.createDirectory(distributionFile.resolveSibling("extract"));
logLifecycle("Exploding distribution into '" + explodeTargetDirectory + "'");
final ExplodeSettings explodeSettings = new ExplodeSettings(distributionFile, explodeTargetDirectory,
settings.getOsName());
final Optional<String> distributionFileExtension = Utils
.getExtension(distributionFile.getFileName().toString()).flatMap(extension -> {
.getExtension(distributionFile.getFileName().toString())
.flatMap(extension -> {
final Optional<String> newExtension;
if (Utils.isGzipExtension(extension)) {
newExtension = Utils
Expand All @@ -78,35 +80,40 @@ public void install() throws DistributionInstallerException {
}
return newExtension;
});
distributionFileExtension.flatMap(extension -> settings.getArchiverFactory().get(extension))
.orElseThrow(UnsupportedDistributionArchiveException::new).explode(explodeSettings);
distributionFileExtension
.flatMap(extension -> settings.getArchiverFactory().get(extension))
.orElseThrow(UnsupportedDistributionArchiveException::new)
.explode(explodeSettings);

logLifecycle("Moving distribution into '" + settings.getInstallDirectory() + "'");
// Removes the root directory of exploded content, if relevant.
final Set<Path> distributionFiles;
try (final Stream<Path> childFiles = Files.list(distributionFile.getParent())) {
try (final Stream<Path> childFiles = Files.list(explodeTargetDirectory)) {
distributionFiles = childFiles
.filter(childFile -> !childFile.getFileName().equals(distributionFile.getFileName()))
.collect(toSet());
}
final Path distributionRootDirectory;
if (distributionFiles.size() == 1) {
final Path distributionRootDirectory = distributionFiles.iterator().next();
Utils.moveFiles(distributionRootDirectory, distributionFile.getParent());
Files.delete(distributionRootDirectory);
distributionRootDirectory = distributionFiles.iterator().next();
} else {
distributionRootDirectory = explodeTargetDirectory;
}
Utils.moveFileTree(distributionRootDirectory, settings.getInstallDirectory());

logLifecycle("Removing explode directory '" + explodeTargetDirectory + "'");
Files.deleteIfExists(explodeTargetDirectory);
logLifecycle("Removing distribution file '" + distributionFile + "'");
Files.delete(distributionFile);

logLifecycle("Distribution installed in '" + distributionFile.getParent() + "'");
logLifecycle("Distribution installed in '" + settings.getInstallDirectory() + "'");
} catch (final IOException | DistributionUrlResolverException | DownloadException | DistributionValidatorException | UnsupportedDistributionArchiveException | UnsupportedEntryException | SlipAttackException | ArchiverException e) {
throw new DistributionInstallerException(e);
}
}

private void checkInstallDirectory() throws IOException {
Files.createDirectories(settings.getInstallDirectory());

logLifecycle("Removing content in install directory '" + settings.getInstallDirectory() + "'.");
Utils.deleteRecursively(settings.getInstallDirectory(), false);
private void deleteInstallDirectory() throws IOException {
logLifecycle("Removing install directory '" + settings.getInstallDirectory() + "'.");
Utils.deleteFileTree(settings.getInstallDirectory(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DistributionInstallerSettings {

private final String osName;

private final Path temporaryDirectory;

/**
* Directory where the distribution shall be installed.
*/
Expand Down Expand Up @@ -53,11 +55,12 @@ public class DistributionInstallerSettings {
* @param archiverFactory Factory providing archivers.
* @param installDirectory Install directory.
*/
public DistributionInstallerSettings(final Task task, final String osName,
public DistributionInstallerSettings(final Task task, final String osName, final Path temporaryDirectory,
final DistributionUrlResolver urlResolver, final Downloader downloader, final DistributionValidator validator,
final ArchiverFactory archiverFactory, final Path installDirectory) {
this.task = task;
this.osName = osName;
this.temporaryDirectory = temporaryDirectory;
this.urlResolver = urlResolver;
this.downloader = downloader;
this.validator = validator;
Expand All @@ -83,6 +86,10 @@ public String getOsName() {
return osName;
}

public Path getTemporaryDirectory() {
return temporaryDirectory;
}

/**
* Gets the install directory.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.siouan.frontendgradleplugin.core;

/**
* Exception thrown when no script was provided.
*
* @since 1.3.0
*/
public class MissingScriptException extends FrontendException {}
Loading

0 comments on commit 2c2f2c0

Please sign in to comment.