Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit b0c4bac

Browse files
authored
Issue48 (#50)
* Add default constructor for FormData * Add maven wrapper * update version
1 parent 6d0a45a commit b0c4bac

File tree

10 files changed

+582
-14
lines changed

10 files changed

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

.mvn/wrapper/maven-wrapper.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ jdk:
55
- oraclejdk8
66

77
install:
8-
mvn --settings .settings.xml install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip -B -V
8+
./mvnw --settings .settings.xml install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip -B -V
99

1010
script:
11-
mvn --settings .settings.xml clean verify -DskipTests=false -Dmaven.javadoc.skip=true -Dgpg.skip -B -U
11+
./mvnw --settings .settings.xml clean verify -DskipTests=false -Dmaven.javadoc.skip=true -Dgpg.skip -B -U
1212

1313
before_deploy:
14-
- mvn help:evaluate -N -Dexpression=project.version | grep -v '\['
15-
- export project_version=$(mvn help:evaluate -N -Dexpression=project.version | grep -v '\[')
14+
- ./mvnw help:evaluate -N -Dexpression=project.version | grep -v '\['
15+
- export project_version=$(./mvnw help:evaluate -N -Dexpression=project.version | grep -v '\[')
1616
- echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import
1717
- echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust
1818
- sed -i -- "s/\${env.SONATYPE_PASSWORD}/$SONATYPE_PASSWORD/g" .settings.xml
19-
- mvn --settings .settings.xml clean deploy -DskipTests=true -Dmaven.javadoc.skip=false -B -U
19+
- ./mvnw --settings .settings.xml clean deploy -DskipTests=true -Dmaven.javadoc.skip=false -B -U
2020

2121
deploy:
2222
provider: releases

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Include the dependency to your project's pom.xml file:
1515
<dependency>
1616
<groupId>io.github.openfeign.form</groupId>
1717
<artifactId>feign-form</artifactId>
18-
<version>3.4.0</version>
18+
<version>3.4.1</version>
1919
</dependency>
2020
...
2121
</dependencies>
@@ -124,12 +124,12 @@ Include the dependencies to your project's pom.xml file:
124124
<dependency>
125125
<groupId>io.github.openfeign.form</groupId>
126126
<artifactId>feign-form</artifactId>
127-
<version>3.4.0</version>
127+
<version>3.4.1</version>
128128
</dependency>
129129
<dependency>
130130
<groupId>io.github.openfeign.form</groupId>
131131
<artifactId>feign-form-spring</artifactId>
132-
<version>3.4.0</version>
132+
<version>3.4.1</version>
133133
</dependency>
134134
...
135135
</dependencies>

feign-form-spring/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ limitations under the License.
2727
<parent>
2828
<groupId>io.github.openfeign.form</groupId>
2929
<artifactId>parent</artifactId>
30-
<version>3.4.0</version>
30+
<version>3.4.1</version>
3131
</parent>
3232

3333
<name>Open Feign Forms Extension for Spring</name>

feign-form/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ limitations under the License.
2727
<parent>
2828
<groupId>io.github.openfeign.form</groupId>
2929
<artifactId>parent</artifactId>
30-
<version>3.4.0</version>
30+
<version>3.4.1</version>
3131
</parent>
3232

3333
<name>Open Feign Forms Core</name>

feign-form/src/main/java/feign/form/FormData.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616

1717
package feign.form;
1818

19+
import static lombok.AccessLevel.PRIVATE;
20+
1921
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20-
import lombok.Value;
22+
import lombok.AllArgsConstructor;
23+
import lombok.Builder;
24+
import lombok.Data;
25+
import lombok.NoArgsConstructor;
26+
import lombok.experimental.FieldDefaults;
2127

2228
/**
2329
* This object encapsulates a byte array and its associated content type.
@@ -26,7 +32,11 @@
2632
* @author Guillaume Simard
2733
* @since 24.03.2018
2834
*/
29-
@Value
35+
@Data
36+
@Builder
37+
@NoArgsConstructor
38+
@AllArgsConstructor
39+
@FieldDefaults(level = PRIVATE)
3040
@SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
3141
public class FormData {
3242

0 commit comments

Comments
 (0)