Skip to content

Commit

Permalink
support activator clean stage
Browse files Browse the repository at this point in the history
  • Loading branch information
fliptoo committed May 20, 2016
1 parent 760afdc commit 5805bac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ Please refer [Play!](https://www.playframework.com/documentation/1.3.x/jpa#aname
## Installation
Add plugin declarations into your plugins.sbt file:
```
addSbtPlugin("com.fliptoo" % "sbt-playjpa" % "1.0.1")
addSbtPlugin("com.fliptoo" % "sbt-playjpa" % "1.0.0" excludeAll(ExclusionRule(organization = "com.typesafe.play"))
```
Add dependency declarations into your build.sbt file:
```
"com.fliptoo" % "playjpa" % "1.0.1"
"com.fliptoo" % "playjpa" % "1.0.0" excludeAll(ExclusionRule(organization = "com.typesafe.play")
```
## Improvement
This is my first time development on SBT Plugin, i am looking for a way to avoid using `excludeAll(ExclusionRule(organization = "com.typesafe.play"` due to `conflicting cross version suffixes`. Hopefully some one can assist on this improvement. Thanks a lot!

## Quick Start

Extend your JPA entity with the Model class
Expand Down
13 changes: 7 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
lazy val root = project
.in(file("."))
.settings(
name := "playjpa-root",
scalaVersion := "2.11.8",
name := "playjpa-root",
packagedArtifacts := Map.empty,
publishLocal := {},
publish := {}
Expand All @@ -11,16 +11,17 @@ lazy val root = project

lazy val core = project
.in(file("playjpa"))
.enablePlugins(PlayJava)
.settings(
libraryDependencies ++= Seq(
"com.typesafe.play" % "play_2.11" % "2.5.3" intransitive,
"com.typesafe.play" % "play-java-jpa_2.11" % "2.5.3" intransitive,
javaJpa,
"org.hibernate" % "hibernate-entitymanager" % "5.1.0.Final",
"org.apache.commons" % "commons-lang3" % "3.4",
"javax.inject" % "javax.inject" % "1"
),
scalaVersion := "2.11.8",
name := "playjpa",
version := "1.0.1",
version := "1.0.0",
organization := "com.fliptoo",
autoScalaLibrary := false,
crossPaths := false
Expand All @@ -31,9 +32,9 @@ lazy val plugin = project
.dependsOn(core)
.settings(
name := "sbt-playjpa",
version := "1.0.1",
version := "1.0.0",
organization := "com.fliptoo",
sbtPlugin := true,
autoScalaLibrary := false,
crossPaths := false
)
)
8 changes: 4 additions & 4 deletions playjpa/src/main/java/com/fliptoo/playjpa/Enhancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class Enhancer {

public abstract void enhance(CtClass cc, String Entity, String Model, String JPAQuery, String JPQL);

protected static void makeMethod(String method, CtClass cc) {
public static void makeMethod(String method, CtClass cc) {
try {
CtMethod cm = CtMethod.make(method, cc);
cc.addMethod(cm);
Expand All @@ -20,17 +20,17 @@ protected static void makeMethod(String method, CtClass cc) {
catch (Exception e) {e.printStackTrace();}
}

protected static void createAnnotation(AnnotationsAttribute attribute, Class<? extends java.lang.annotation.Annotation> annotationType, String memberKey, MemberValue memberValue) {
public static void createAnnotation(AnnotationsAttribute attribute, Class<? extends java.lang.annotation.Annotation> annotationType, String memberKey, MemberValue memberValue) {
Annotation annotation = new Annotation(annotationType.getName(), attribute.getConstPool());
annotation.addMemberValue(memberKey, memberValue);
attribute.addAnnotation(annotation);
}

protected static boolean hasAnnotation(CtClass ctClass, Class<? extends java.lang.annotation.Annotation> annotationType) throws ClassNotFoundException {
public static boolean hasAnnotation(CtClass ctClass, Class<? extends java.lang.annotation.Annotation> annotationType) throws ClassNotFoundException {
return getAnnotations(ctClass).getAnnotation(annotationType.getName()) != null;
}

protected static AnnotationsAttribute getAnnotations(CtClass ctClass) {
public static AnnotationsAttribute getAnnotations(CtClass ctClass) {
AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctClass.getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
if (annotationsAttribute == null) {
annotationsAttribute = new AnnotationsAttribute(ctClass.getClassFile().getConstPool(), AnnotationsAttribute.visibleTag);
Expand Down
11 changes: 5 additions & 6 deletions playjpa/src/main/java/com/fliptoo/playjpa/PlayJpa.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public ClassPathWithFile(String classPath, File file) {
}
}

private static final String Model = Model.class.getCanonicalName();
private static final String JPAQuery = JPQL.JPAQuery.class.getCanonicalName();
private static final String Model = com.fliptoo.playjpa.Model.class.getCanonicalName();
private static final String JPAQuery = com.fliptoo.playjpa.JPQL.JPAQuery.class.getCanonicalName();
private static final String JPQL = JPQL.class.getCanonicalName();
private static final String Enhancer = Enhancer.class.getCanonicalName();
private static final Enhancers enhancers = new Enhancers();
private static List<ClassPathWithFile> entities = new ArrayList<>();

Expand Down Expand Up @@ -85,12 +84,12 @@ public static boolean scan(String classPath, File classFile) {
cp.appendSystemPath();
cp.appendPathList(classPath);
CtClass model = cp.get(Model);
CtClass enhancer = cp.get(Enhancer);
CtClass enhancer = cp.get(Enhancer.class.getCanonicalName());
try (FileInputStream is = new FileInputStream(classFile)) {
CtClass cc = cp.makeClass(is);
if (cc.subtypeOf(enhancer)) {
enhancers.get().add((Enhancer) cp.getAndRename(cc.getName(),
cc.getName() + "-" + UUID.randomUUID().toString()).toClass().newInstance());
cc = cp.getAndRename(cc.getName(), cc.getName() + UUID.randomUUID().toString());
enhancers.get().add((Enhancer) cc.toClass(Enhancer.class.getClassLoader(), null).newInstance());
return true;
}
if (!hasAnnotation(cc, Entity.class)) return false;
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
logLevel := Level.Warn

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.3")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

0 comments on commit 5805bac

Please sign in to comment.