Skip to content

Commit 9115a18

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 6a5b862 + 8a33d7e commit 9115a18

File tree

18 files changed

+765
-22
lines changed

18 files changed

+765
-22
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
Unless required by applicable law or agreed to in writing,
11+
software distributed under the License is distributed on an
12+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
KIND, either express or implied. See the License for the
14+
specific language governing permissions and limitations
15+
under the License.
16+
*/
17+
18+
import java.net.*;
19+
import java.io.*;
20+
import java.nio.channels.*;
21+
import java.util.Properties;
22+
23+
public class MavenWrapperDownloader {
24+
25+
/**
26+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
27+
*/
28+
private static final String DEFAULT_DOWNLOAD_URL =
29+
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
30+
31+
/**
32+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
33+
* use instead of the default one.
34+
*/
35+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
36+
".mvn/wrapper/maven-wrapper.properties";
37+
38+
/**
39+
* Path where the maven-wrapper.jar will be saved to.
40+
*/
41+
private static final String MAVEN_WRAPPER_JAR_PATH =
42+
".mvn/wrapper/maven-wrapper.jar";
43+
44+
/**
45+
* Name of the property which should be used to override the default download url for the wrapper.
46+
*/
47+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
48+
49+
public static void main(String args[]) {
50+
System.out.println("- Downloader started");
51+
File baseDirectory = new File(args[0]);
52+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
53+
54+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
55+
// wrapperUrl parameter.
56+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
57+
String url = DEFAULT_DOWNLOAD_URL;
58+
if(mavenWrapperPropertyFile.exists()) {
59+
FileInputStream mavenWrapperPropertyFileInputStream = null;
60+
try {
61+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
62+
Properties mavenWrapperProperties = new Properties();
63+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
64+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
65+
} catch (IOException e) {
66+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
67+
} finally {
68+
try {
69+
if(mavenWrapperPropertyFileInputStream != null) {
70+
mavenWrapperPropertyFileInputStream.close();
71+
}
72+
} catch (IOException e) {
73+
// Ignore ...
74+
}
75+
}
76+
}
77+
System.out.println("- Downloading from: : " + url);
78+
79+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
80+
if(!outputFile.getParentFile().exists()) {
81+
if(!outputFile.getParentFile().mkdirs()) {
82+
System.out.println(
83+
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
84+
}
85+
}
86+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
87+
try {
88+
downloadFileFromURL(url, outputFile);
89+
System.out.println("Done");
90+
System.exit(0);
91+
} catch (Throwable e) {
92+
System.out.println("- Error downloading");
93+
e.printStackTrace();
94+
System.exit(1);
95+
}
96+
}
97+
98+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
99+
URL website = new URL(urlString);
100+
ReadableByteChannel rbc;
101+
rbc = Channels.newChannel(website.openStream());
102+
FileOutputStream fos = new FileOutputStream(destination);
103+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
104+
fos.close();
105+
rbc.close();
106+
}
107+
108+
}

.mvn/wrapper/maven-wrapper.jar

46.7 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
sudo: required
1+
# To let the CI execute the maven wrapper, use this command and push the change:
2+
# git update-index --chmod=+x mvnw
3+
24
language: java
35
install: true
46
jdk:
@@ -14,14 +16,14 @@ before_install:
1416
- tar xvf secrets.tar
1517

1618
script:
17-
- mvn clean install -X -Djarsigner.skip=false checkstyle:check
19+
- ./mvnw clean install -X -Djarsigner.skip=false checkstyle:check
1820

1921
after_success:
20-
- mvn test jacoco:report coveralls:report
22+
- ./mvnw test jacoco:report coveralls:report
2123

2224
deploy:
2325
- provider: script
24-
script: mvn -s ci-settings.xml deploy -X
26+
script: ./mvnw -s ci-settings.xml deploy -X
2527
skip_cleanup: true
2628
on:
2729
branch: master

CHANGELOG

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Releases
22

3+
## v0.6.0
4+
5+
* add `encodeCharsetToBytes()` feature #7
6+
* add new `from(char[] charArray, Charset charset)` constructor with improved logic #8
7+
38
## v0.5.0
9+
410
* better resource handling for compression
511
* add nullSafe from() constructor
612
* rename `toObjectArray()` to `toBoxedArray()` (will be removed in 1.0)
713
* add appendNullSafe and append string with encoding
14+
* add proguard optimized version (can be used with classifier 'optimized')
15+
* add constant time equals
16+
* fix or() operator using and() internally #2
817

918
## v0.4.6
1019

@@ -63,4 +72,4 @@
6372

6473
## v0.2.0
6574

66-
initial version
75+
initial version

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bytes
1+
# Bytes Utility Library for Java
22

33
Bytes is a utility library that makes it easy to **create**, **parse**, **transform**,
44
**validate** and **convert** byte arrays in Java. It's main class `Bytes` is
@@ -53,6 +53,8 @@ Add dependency to your `pom.xml` ([check latest release](https://github.com/patr
5353
<version>{latest-version}</version>
5454
</dependency>
5555

56+
_Note:_ There is a byte-code optimized version (powerd by [ProGuard](https://www.guardsquare.com/en/products/proguard)) which can be used with [classifier](https://maven.apache.org/pom.html#Maven_Coordinates) 'optimized'. This may have issues so use at your own risk.
57+
5658
Some simple examples:
5759

5860
```java
@@ -374,6 +376,8 @@ Bytes.wrap(array).entropy();
374376
Of course all standard Java Object methods are implemented including:
375377
`hashCode()`, `equals()`, `toString()` as well as it being
376378
[`Comparable`](https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html).
379+
In addition there is a constant time `equalsConstantTime()` method, see [here](https://codahale.com/a-lesson-in-timing-attacks/) why this
380+
might be useful.
377381

378382
The `toString()` methods only shows the length and a preview of maximal 8 bytes:
379383

misc/icon.png

-1.1 KB
Loading

misc/icon.psd

-268 KB
Binary file not shown.

0 commit comments

Comments
 (0)