Skip to content

Commit da142d8

Browse files
authored
Merge pull request #100 from slonopotamus/closures
Fix API that accepts closures so it an be used from Kotlin
2 parents 8d63061 + 178787b commit da142d8

File tree

6 files changed

+52
-40
lines changed

6 files changed

+52
-40
lines changed

src/com/inet/gradle/appbundler/AppBundlerGradleTask.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
import java.io.File;
2020

21+
import org.gradle.api.Action;
2122
import org.gradle.api.GradleException;
2223
import org.gradle.api.internal.project.ProjectInternal;
2324
import org.gradle.api.tasks.TaskAction;
24-
import org.gradle.util.ConfigureUtil;
2525

2626
import com.inet.gradle.setup.abstracts.AbstractTask;
2727

@@ -75,11 +75,12 @@ public void action() {
7575
/**
7676
* Set the needed information for signing the setup.
7777
*
78-
* @param closure the data for signing
78+
* @param action the data for signing
7979
*/
80-
public void codeSign( Closure<AppBundler> closure ) {
80+
public void codeSign( Action<? super OSXCodeSign<? super AppBundlerGradleTask,? super AppBundler>> action ) {
8181
ProjectInternal project = (ProjectInternal)getProject();
82-
codeSign = ConfigureUtil.configure( closure, new OSXCodeSign<AppBundlerGradleTask,AppBundler>(this, project.getFileResolver()) );
82+
codeSign = new OSXCodeSign<>(this, project.getFileResolver());
83+
action.execute(codeSign);
8384
}
8485

8586
/**

src/com/inet/gradle/appbundler/OSXCodeSign.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import java.nio.file.Files;
77
import java.util.ArrayList;
88

9+
import org.gradle.api.Action;
910
import org.gradle.api.internal.file.FileResolver;
1011
import org.gradle.api.internal.project.ProjectInternal;
11-
import org.gradle.util.ConfigureUtil;
1212

1313
import com.inet.gradle.setup.abstracts.AbstractBuilder;
1414
import com.inet.gradle.setup.abstracts.AbstractSetupBuilder;
@@ -331,11 +331,12 @@ public void notarize( File notarizeFile ) {
331331

332332
/**
333333
* Set the notarization information
334-
* @param closure the notarization information
334+
* @param action the notarization information
335335
*/
336-
public void notarization( Closure<OSXNotarize<T, S>> closure ) {
336+
public void notarization( Action<? super OSXNotarize<? super T, ? super S>> action ) {
337337
ProjectInternal project = (ProjectInternal)task.getProject();
338-
this.notarization = ConfigureUtil.configure( closure, new OSXNotarize<T, S>(getTask(), project.getFileResolver(), this) );
338+
this.notarization = new OSXNotarize<T, S>(getTask(), project.getFileResolver(), this);
339+
action.execute(this.notarization);
339340
}
340341

341342
/**

src/com/inet/gradle/setup/SetupBuilder.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23+
import org.gradle.api.Action;
2324
import org.gradle.api.Project;
24-
import org.gradle.util.ConfigureUtil;
2525

2626
import com.inet.gradle.setup.abstracts.AbstractSetupBuilder;
2727
import com.inet.gradle.setup.abstracts.DesktopStarter;
@@ -127,10 +127,11 @@ public void setRunAfter( String runAfter ) {
127127
/**
128128
* Set a command that run after the installer.
129129
*
130-
* @param closure the command
130+
* @param action the command
131131
*/
132-
public void runAfter( Closure<?> closure ) {
133-
runAfter = ConfigureUtil.configure( closure, new DesktopStarter( this ) );
132+
public void runAfter( Action<? super DesktopStarter> action ) {
133+
runAfter = new DesktopStarter( this );
134+
action.execute(runAfter);
134135
}
135136

136137
/**
@@ -155,19 +156,21 @@ public void setRunBeforeUninstall( String runAfter ) {
155156
/**
156157
* Set a command that run run before the uninstaller.
157158
*
158-
* @param closue the command
159+
* @param action the command
159160
*/
160-
public void runBeforeUninstall( Closure<DesktopStarter> closue ) {
161-
runBeforeUninstall = ConfigureUtil.configure( closue, new DesktopStarter( this ) );
161+
public void runBeforeUninstall( Action<? super DesktopStarter> action ) {
162+
runBeforeUninstall = new DesktopStarter( this );
163+
action.execute(runBeforeUninstall);
162164
}
163165

164166
/**
165167
* Register a service.
166168
*
167-
* @param closue the closure of the service definition
169+
* @param action the closure of the service definition
168170
*/
169-
public void service( Closure<Service> closue ) {
170-
Service service = ConfigureUtil.configure( closue, new Service( this ) );
171+
public void service( Action<? super Service> action ) {
172+
Service service = new Service( this );
173+
action.execute(service);
171174
services.add( service );
172175
}
173176

@@ -183,10 +186,11 @@ public List<Service> getServices() {
183186
/**
184187
* Register a desktop starter.
185188
*
186-
* @param closue the closure of the desktop starter's definition
189+
* @param action the closure of the desktop starter's definition
187190
*/
188-
public void desktopStarter( Closure<?> closue ) {
189-
DesktopStarter service = ConfigureUtil.configure( closue, new DesktopStarter( this ) );
191+
public void desktopStarter( Action<? super DesktopStarter> action ) {
192+
DesktopStarter service = new DesktopStarter( this );
193+
action.execute(service);
190194
desktopStarters.add( service );
191195
}
192196

src/com/inet/gradle/setup/abstracts/DesktopStarter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.gradle.api.Action;
2223
import org.gradle.api.GradleException;
23-
import org.gradle.util.ConfigureUtil;
2424

2525
import groovy.lang.Closure;
2626

@@ -114,10 +114,11 @@ public static enum Location {
114114
/**
115115
* Register a file extensions.
116116
*
117-
* @param closue document type
117+
* @param action document type
118118
*/
119-
public void documentType( Closure<?> closue ) {
120-
DocumentType doc = ConfigureUtil.configure( closue, new DocumentType( setup ) );
119+
public void documentType( Action<? super DocumentType> action ) {
120+
DocumentType doc = new DocumentType( setup );
121+
action.execute(doc);
121122
if( doc.getFileExtension() == null || doc.getFileExtension().size() == 0 ) {
122123
throw new GradleException( "The documentType has to contain at least one file extension." );
123124
}

src/com/inet/gradle/setup/dmg/Dmg.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.util.stream.Collectors;
2424

2525
import org.apache.tools.ant.types.FileSet;
26+
import org.gradle.api.Action;
2627
import org.gradle.api.internal.project.ProjectInternal;
27-
import org.gradle.util.ConfigureUtil;
2828

2929
import com.inet.gradle.appbundler.OSXCodeSign;
3030
import com.inet.gradle.setup.SetupBuilder;
@@ -254,11 +254,12 @@ public void setFontSize( int fontSize ) {
254254
/**
255255
* Set the needed information for signing the setup.
256256
*
257-
* @param closure the data for signing
257+
* @param action the data for signing
258258
*/
259-
public void setCodeSign( Closure<OSXCodeSign<Dmg, SetupBuilder>> closure ) {
259+
public void setCodeSign( Action<? super OSXCodeSign<? super Dmg,? super SetupBuilder>> action ) {
260260
ProjectInternal project = (ProjectInternal)getProject();
261-
codeSign = ConfigureUtil.configure( closure, new OSXCodeSign<Dmg, SetupBuilder>( this, project.getFileResolver() ) );
261+
codeSign = new OSXCodeSign<>(this, project.getFileResolver());
262+
action.execute(codeSign);
262263
}
263264

264265
/**
@@ -385,10 +386,12 @@ public List<PreferencesLink> getPreferencesLinks() {
385386
/**
386387
* Set a preferences link
387388
*
388-
* @param link the link
389+
* @param action the link
389390
*/
390-
public void preferencesLink( Object link ) {
391-
preferencesLink.add( ConfigureUtil.configure( (Closure<?>)link, new PreferencesLink() ) );
391+
public void preferencesLink( Action<? super PreferencesLink> action ) {
392+
final PreferencesLink link = new PreferencesLink();
393+
action.execute(link);
394+
preferencesLink.add(link);
392395
}
393396

394397
/**

src/com/inet/gradle/setup/msi/Msi.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
import java.util.Collections;
2626
import java.util.List;
2727

28+
import org.gradle.api.Action;
2829
import org.gradle.api.GradleException;
2930
import org.gradle.api.internal.file.CopyActionProcessingStreamAction;
3031
import org.gradle.api.internal.project.ProjectInternal;
3132
import org.gradle.api.tasks.Input;
3233
import org.gradle.api.tasks.InputFile;
3334
import org.gradle.api.tasks.InputFiles;
34-
import org.gradle.util.ConfigureUtil;
3535

3636
import com.inet.gradle.setup.abstracts.AbstractSetupTask;
3737
import com.inet.gradle.setup.util.ResourceUtils;
@@ -219,10 +219,11 @@ public void setDialogBmp( Object dialogBmp ) {
219219
/**
220220
* Set the needed information for signing the setup.
221221
*
222-
* @param closue the data for signing
222+
* @param action the data for signing
223223
*/
224-
public void signTool( Closure<SignTool> closue ) {
225-
signTool = ConfigureUtil.configure( closue, new SignTool() );
224+
public void signTool( Action<? super SignTool> action ) {
225+
signTool = new SignTool();
226+
action.execute(signTool);
226227
}
227228

228229
/**
@@ -352,10 +353,11 @@ public void setMinOS( double minVersion ) {
352353
/**
353354
* Register a lauch4j configuration. Every configuration create an *.exe file with the given settings.
354355
*
355-
* @param closue the closure of the launch4j definition
356+
* @param action the closure of the launch4j definition
356357
*/
357-
public void launch4j( Closure<Launch4j> closue ) {
358-
Launch4j launcher = ConfigureUtil.configure( closue, new Launch4j( getSetupBuilder() ) );
358+
public void launch4j( Action<Launch4j> action ) {
359+
Launch4j launcher = new Launch4j( getSetupBuilder() );
360+
action.execute(launcher);
359361
launch4j.add( launcher );
360362
}
361363

@@ -558,4 +560,4 @@ public boolean isSkipValidation() {
558560
public void setSkipValidation( boolean skipValidation ) {
559561
this.skipValidation = skipValidation;
560562
}
561-
}
563+
}

0 commit comments

Comments
 (0)