Skip to content

Commit 0ac70c3

Browse files
committed
joobyRun gradle plugin fix #412
1 parent 7cd9938 commit 0ac70c3

File tree

9 files changed

+455
-6
lines changed

9 files changed

+455
-6
lines changed

jooby-gradle-plugin/pom.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<groupId>org.jooby</groupId>
7+
<artifactId>jooby-project</artifactId>
8+
<version>1.0.0.CR6</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>jooby-gradle-plugin</artifactId>
13+
14+
<name>gradle plugin</name>
15+
16+
<build>
17+
<plugins>
18+
<!-- sure-fire -->
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-surefire-plugin</artifactId>
22+
<configuration>
23+
<includes>
24+
<include>**/*Test.java</include>
25+
<include>**/*Feature.java</include>
26+
<include>**/Issue*.java</include>
27+
</includes>
28+
</configuration>
29+
</plugin>
30+
31+
</plugins>
32+
</build>
33+
34+
<dependencies>
35+
<!-- jooby:run -->
36+
<dependency>
37+
<groupId>org.jooby</groupId>
38+
<artifactId>jooby-run</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
42+
<!-- gradle -->
43+
<dependency>
44+
<groupId>org.gradle</groupId>
45+
<artifactId>gradle-core</artifactId>
46+
<version>2.5</version>
47+
<scope>provided</scope>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.gradle</groupId>
52+
<artifactId>gradle-plugins</artifactId>
53+
<version>0.9-rc-1</version>
54+
<scope>provided</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.codehaus.groovy</groupId>
59+
<artifactId>groovy</artifactId>
60+
<version>2.4.7</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>javax.inject</groupId>
66+
<artifactId>javax.inject</artifactId>
67+
<version>1</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
71+
<!-- Test dependencies -->
72+
<dependency>
73+
<groupId>org.jooby</groupId>
74+
<artifactId>jooby</artifactId>
75+
<version>${project.version}</version>
76+
<scope>test</scope>
77+
<classifier>tests</classifier>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>junit</groupId>
82+
<artifactId>junit</artifactId>
83+
<scope>test</scope>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>org.easymock</groupId>
88+
<artifactId>easymock</artifactId>
89+
<scope>test</scope>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>org.powermock</groupId>
94+
<artifactId>powermock-api-easymock</artifactId>
95+
<scope>test</scope>
96+
</dependency>
97+
98+
<dependency>
99+
<groupId>org.powermock</groupId>
100+
<artifactId>powermock-module-junit4</artifactId>
101+
<scope>test</scope>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>org.jacoco</groupId>
106+
<artifactId>org.jacoco.agent</artifactId>
107+
<classifier>runtime</classifier>
108+
<scope>test</scope>
109+
</dependency>
110+
111+
</dependencies>
112+
113+
<repositories>
114+
<repository>
115+
<id>central</id>
116+
<name>central</name>
117+
<url>http://repo2.maven.org</url>
118+
</repository>
119+
<repository>
120+
<id>jcenter</id>
121+
<name>jcenter</name>
122+
<url>http://jcenter.bintray.com</url>
123+
</repository>
124+
</repositories>
125+
126+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
package org.jooby.run;
20+
21+
import java.io.File;
22+
import java.util.HashMap;
23+
import java.util.LinkedHashSet;
24+
import java.util.Map;
25+
import java.util.Set;
26+
27+
import org.gradle.api.Plugin;
28+
import org.gradle.api.Project;
29+
import org.gradle.api.Task;
30+
import org.gradle.api.internal.ConventionMapping;
31+
import org.gradle.api.invocation.Gradle;
32+
import org.gradle.api.plugins.Convention;
33+
import org.gradle.api.plugins.JavaPluginConvention;
34+
import org.gradle.api.tasks.SourceSet;
35+
36+
public class JoobyPlugin implements Plugin<Project> {
37+
38+
@Override
39+
public void apply(final Project project) {
40+
JoobyPluginConvention jettyConvention = new JoobyPluginConvention();
41+
Convention convention = project.getConvention();
42+
convention.getPlugins().put("jooby", jettyConvention);
43+
44+
configureJoobyRun(project);
45+
}
46+
47+
private void configureJoobyRun(final Project project) {
48+
project.getTasks()
49+
.withType(JoobyTask.class, joobyRun -> {
50+
ConventionMapping mapping = joobyRun.getConventionMapping();
51+
mapping.map("classpath", () -> {
52+
SourceSet sourceSet = getJavaConvention(project).getSourceSets()
53+
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
54+
55+
Set<File> cp = new LinkedHashSet<>();
56+
// conf & public
57+
sourceSet.getResources().getSrcDirs().forEach(cp::add);
58+
// classes/main, resources/main + jars
59+
sourceSet.getRuntimeClasspath().getFiles().forEach(cp::add);
60+
61+
return cp;
62+
});
63+
64+
mapping.map("mainClassName", () -> project.getProperties().get("mainClassName"));
65+
66+
Gradle gradle = project.getGradle();
67+
mapping.map("block", () -> !gradle.getStartParameter().isContinuous());
68+
mapping.map("logLevel", () -> gradle.getStartParameter().getLogLevel().name());
69+
});
70+
71+
Map<String, Object> options = new HashMap<>();
72+
options.put(Task.TASK_TYPE, JoobyTask.class);
73+
options.put(Task.TASK_DEPENDS_ON, new String[]{"processResources", "compileJava" });
74+
options.put(Task.TASK_NAME, "joobyRun");
75+
options.put(Task.TASK_GROUP, "jooby");
76+
project.getTasks().create(options);
77+
}
78+
79+
public JavaPluginConvention getJavaConvention(final Project project) {
80+
return project.getConvention().getPlugin(JavaPluginConvention.class);
81+
}
82+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* This copy of Woodstox XML processor is licensed under the
21+
* Apache (Software) License, version 2.0 ("the License").
22+
* See the License for details about distribution rights, and the
23+
* specific rights regarding derivate works.
24+
*
25+
* You may obtain a copy of the License at:
26+
*
27+
* http://www.apache.org/licenses/
28+
*
29+
* A copy is also included in the downloadable source code package
30+
* containing Woodstox, in file "ASL2.0", under the same directory
31+
* as this file.
32+
*/
33+
package org.jooby.run;
34+
35+
import java.util.List;
36+
37+
public class JoobyPluginConvention {
38+
private List<String> includes;
39+
40+
private List<String> excludes;
41+
42+
private String logLevel = "info";
43+
44+
private boolean block = true;
45+
46+
public List<String> getIncludes() {
47+
return includes;
48+
}
49+
50+
public void setIncludes(final List<String> includes) {
51+
this.includes = includes;
52+
}
53+
54+
public List<String> getExcludes() {
55+
return excludes;
56+
}
57+
58+
public void setExcludes(final List<String> excludes) {
59+
this.excludes = excludes;
60+
}
61+
62+
public String getLogLevel() {
63+
return logLevel;
64+
}
65+
66+
public void setLogLevel(final String logLevel) {
67+
this.logLevel = logLevel;
68+
}
69+
70+
public boolean isBlock() {
71+
return block;
72+
}
73+
74+
public void setBlock(final boolean block) {
75+
this.block = block;
76+
}
77+
78+
}

0 commit comments

Comments
 (0)