-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Set executable bit when unpacking Zip files. Fixes #752
- Loading branch information
Showing
13 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/jreleaser-utils/src/test/java/org/jreleaser/test/Platform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2020-2022 The JReleaser authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jreleaser.test; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.0.0 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(PlatformCondition.class) | ||
public @interface Platform { | ||
boolean match() default true; | ||
|
||
String platform() default ""; | ||
} |
53 changes: 53 additions & 0 deletions
53
core/jreleaser-utils/src/test/java/org/jreleaser/test/PlatformCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2020-2022 The JReleaser authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jreleaser.test; | ||
|
||
import org.jreleaser.util.PlatformUtils; | ||
import org.jreleaser.util.SimpleJReleaserLoggerAdapter; | ||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.0.0 | ||
*/ | ||
public class PlatformCondition implements ExecutionCondition { | ||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
Optional<Platform> optional = findAnnotation(context.getElement(), Platform.class); | ||
if (optional.isPresent()) { | ||
PlatformUtils.resolveCurrentPlatform(new SimpleJReleaserLoggerAdapter()); | ||
Platform annotation = optional.get(); | ||
boolean match = annotation.match(); | ||
String platform = annotation.platform(); | ||
boolean compatible = PlatformUtils.isCompatible(platform, PlatformUtils.getCurrentFull()); | ||
boolean result = match == compatible; | ||
if (result) { | ||
return ConditionEvaluationResult.enabled("Platform " + platform + " matches"); | ||
} else { | ||
return ConditionEvaluationResult.disabled("Platform " + platform + " did not match"); | ||
} | ||
} | ||
return ConditionEvaluationResult.enabled("Nothing to match"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
core/jreleaser-utils/src/test/java/org/jreleaser/util/FileUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2020-2022 The JReleaser authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jreleaser.util; | ||
|
||
import org.jreleaser.test.Platform; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author Andres Almiray | ||
* @since 1.0.0 | ||
*/ | ||
public class FileUtilsTests { | ||
@ParameterizedTest | ||
@EnumSource(value = FileType.class, | ||
names = {"TAR", "TAR_BZ2", "TAR_GZ", "TAR_XZ", "TBZ2", "TGZ", "TXZ", "ZIP"}) | ||
@Platform(platform = "windows", match = false) | ||
public void unpackArchiveWithExecutable(FileType fileType) throws IOException { | ||
// given: | ||
Path resourcesDir = Paths.get(".") | ||
.resolve("src/test/resources") | ||
.normalize(); | ||
Path archive = resourcesDir.resolve("app-1.0.0" + fileType.extension()); | ||
Path tmp = Files.createTempDirectory(fileType.name()); | ||
|
||
// when: | ||
FileUtils.unpackArchive(archive, tmp, false); | ||
|
||
// then: | ||
Path license = tmp.resolve("app-1.0.0").resolve("LICENSE"); | ||
assertTrue(() -> Files.exists(license), "LICENSE exists"); | ||
Path executable = tmp.resolve("app-1.0.0").resolve("bin/executable"); | ||
assertTrue(() -> Files.exists(executable), "executable exists"); | ||
assertTrue(() -> Files.isExecutable(executable), "executable has executable bit set"); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.