-
-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor gradle plugin to use Gradle best practices
- Loading branch information
Showing
13 changed files
with
306 additions
and
454 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
Binary file modified
BIN
-232 Bytes
(100%)
byte-buddy-gradle-plugin/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions
4
byte-buddy-gradle-plugin/gradle/wrapper/gradle-wrapper.properties
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Aug 30 09:29:34 CEST 2016 | ||
#Wed Aug 31 09:16:34 EEST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip |
33 changes: 0 additions & 33 deletions
33
...ddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractUserConfiguration.java
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/Artifact.java
This file was deleted.
Oops, something went wrong.
104 changes: 55 additions & 49 deletions
104
byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyExtension.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 |
---|---|---|
@@ -1,72 +1,78 @@ | ||
package net.bytebuddy.build.gradle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import groovy.lang.Closure; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Project; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ByteBuddyExtension { | ||
|
||
private final Project project; | ||
private final Project project; | ||
|
||
private List<Transformation> transformations; | ||
|
||
private List<Transformation> transformations; | ||
private Initialization initialization; | ||
|
||
private Initialization initialization; | ||
private String suffix; | ||
|
||
private String suffix; | ||
private boolean failOnLiveInitializer; | ||
|
||
private boolean failOnLiveInitializer; | ||
public ByteBuddyExtension(Project project) { | ||
this.project = project; | ||
transformations = new ArrayList<Transformation>(); | ||
failOnLiveInitializer = true; | ||
} | ||
|
||
public ByteBuddyExtension(Project project) { | ||
this.project = project; | ||
transformations = new ArrayList<Transformation>(); | ||
failOnLiveInitializer = true; | ||
} | ||
private class TransformationsConfigurer { | ||
public Transformation transformation(Closure<?> closure) { | ||
Transformation transformation = (Transformation) project | ||
.configure(new Transformation(), closure); | ||
transformations.add(transformation); | ||
return transformation; | ||
} | ||
} | ||
|
||
public Transformation transformation(Closure<?> closure) { | ||
Transformation transformation = (Transformation) project.configure(new Transformation(project), closure); | ||
transformations.add(transformation); | ||
return transformation; | ||
} | ||
public void transformations(Closure<?> closure) { | ||
project.configure(new TransformationsConfigurer(), closure); | ||
} | ||
|
||
public Initialization initialization(Closure<?> closure) { | ||
if (initialization != null) { | ||
throw new GradleException("Initialization is already set"); | ||
} | ||
Initialization initialization = (Initialization) project.configure(new Initialization(project), closure); | ||
this.initialization = initialization; | ||
return initialization; | ||
} | ||
public Initialization initialization(Closure<?> closure) { | ||
if (initialization != null) { | ||
throw new GradleException("Initialization is already set"); | ||
} | ||
Initialization initialization = (Initialization) project | ||
.configure(new Initialization(), closure); | ||
this.initialization = initialization; | ||
return initialization; | ||
} | ||
|
||
public List<Transformation> getTransformations() { | ||
return transformations; | ||
} | ||
public List<Transformation> getTransformations() { | ||
return transformations; | ||
} | ||
|
||
public Initialization getInitialization() { | ||
return initialization == null | ||
? Initialization.makeDefault(project) | ||
: initialization; | ||
} | ||
public Initialization getInitialization() { | ||
return initialization == null ? Initialization.makeDefault() : initialization; | ||
} | ||
|
||
public void setInitialization(Initialization initialization) { | ||
this.initialization = initialization; | ||
} | ||
public void setInitialization(Initialization initialization) { | ||
this.initialization = initialization; | ||
} | ||
|
||
public String getSuffix() { | ||
return suffix; | ||
} | ||
public String getSuffix() { | ||
return suffix; | ||
} | ||
|
||
public void setSuffix(String suffix) { | ||
this.suffix = suffix; | ||
} | ||
public void setSuffix(String suffix) { | ||
this.suffix = suffix; | ||
} | ||
|
||
public boolean isFailOnLiveInitializer() { | ||
return failOnLiveInitializer; | ||
} | ||
public boolean isFailOnLiveInitializer() { | ||
return failOnLiveInitializer; | ||
} | ||
|
||
public void setFailOnLiveInitializer(boolean failOnLiveInitializer) { | ||
this.failOnLiveInitializer = failOnLiveInitializer; | ||
} | ||
public void setFailOnLiveInitializer(boolean failOnLiveInitializer) { | ||
this.failOnLiveInitializer = failOnLiveInitializer; | ||
} | ||
} |
49 changes: 28 additions & 21 deletions
49
byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyPlugin.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 |
---|---|---|
@@ -1,28 +1,35 @@ | ||
package net.bytebuddy.build.gradle; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.*; | ||
import org.gradle.api.tasks.compile.AbstractCompile; | ||
|
||
public class ByteBuddyPlugin implements Plugin<Project> { | ||
|
||
/* | ||
* TODO: | ||
* | ||
* 1. Create complex configuration (allow nesting and lists). | ||
* 2. Find way to append task to class compilation / test-class compilation. | ||
* 3. Integrate Aether and read (Maven?) repositories from user configuration. | ||
* 4. Read class path / test class path. | ||
* | ||
* Bonus: | ||
* 1. Read explicit dependencies from Maven POM file instead of duplication in build.gradle. | ||
* 2. Are main and test folders of build target customizable locations? | ||
* 3. What GradleExceptions should be thrown? Any sub types? | ||
*/ | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class ByteBuddyPlugin implements Plugin<Project> { | ||
@Override | ||
public void apply(Project project) { | ||
project.getExtensions().create("byteBuddy", ByteBuddyExtension.class, project); | ||
project.getTasks().create("transform", TransformTask.ForProductionTypes.class); | ||
project.getTasks().create("test-transform", TransformTask.ForTestTypes.class); | ||
public void apply(final Project project) { | ||
final ByteBuddyExtension byteBuddyExtension = project.getExtensions() | ||
.create("byteBuddy", ByteBuddyExtension.class, project); | ||
project.getTasks().withType(AbstractCompile.class, new Action<AbstractCompile>() { | ||
@Override | ||
public void execute(AbstractCompile compileTask) { | ||
final Iterable<File> compileClasspathFiles = compileTask.getClasspath(); | ||
final File classesDir = compileTask.getDestinationDir(); | ||
compileTask.doLast(new Action<Task>() { | ||
@Override | ||
public void execute(Task task) { | ||
try { | ||
new Transformer(project, byteBuddyExtension) | ||
.processOutputDirectory(classesDir, | ||
compileClasspathFiles); | ||
} catch (IOException e) { | ||
throw new GradleException( | ||
"Exception in byte-buddy processing", e); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.