Skip to content

Commit 4184ce5

Browse files
committed
refactoring
1 parent c04860b commit 4184ce5

File tree

17 files changed

+673
-564
lines changed

17 files changed

+673
-564
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/target/
22
/nbproject/
33
/.idea/
4-
jbbp.iml
4+
*.iml

jbbp-gradle/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<modelVersion>4.0.0</modelVersion>
55

66
<parent>
7-
<groupId>com.igormaznitsa</groupId>
8-
<artifactId>jbbp-main-pom</artifactId>
9-
<version>1.3.0-SNAPSHOT</version>
10-
<relativePath>../pom.xml</relativePath>
7+
<groupId>com.igormaznitsa</groupId>
8+
<artifactId>jbbp-main-pom</artifactId>
9+
<version>1.3.0-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

1313
<artifactId>jbbp-gradle-plugin</artifactId>
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
package com.igormaznitsa.jbbp.gradle;
22

33
import org.gradle.api.DefaultTask;
4-
import org.gradle.api.file.FileTree;
5-
import org.gradle.api.file.FileVisitDetails;
6-
import org.gradle.api.file.FileVisitor;
7-
import org.gradle.api.file.SourceDirectorySet;
8-
import org.gradle.api.tasks.*;
9-
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;
10-
import org.gradle.language.base.internal.tasks.SimpleStaleClassCleaner;
11-
import org.gradle.language.base.internal.tasks.StaleClassCleaner;
12-
13-
import java.io.File;
4+
import org.gradle.api.tasks.TaskAction;
145

156
public class JBBPTask extends DefaultTask {
167

178
@TaskAction
18-
public void convertJbbp(){
9+
public void doConversion(){
1910
}
2011

2112
}

jbbp-maven/jbbp-maven-plugin/pom.xml

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,10 @@
2020
<id>publish</id>
2121
<build>
2222
<plugins>
23-
<plugin>
24-
<groupId>org.apache.maven.plugins</groupId>
25-
<artifactId>maven-assembly-plugin</artifactId>
26-
<version>2.6</version>
27-
<executions>
28-
<execution>
29-
<id>make-distributive</id>
30-
<phase>install</phase>
31-
<goals>
32-
<goal>single</goal>
33-
</goals>
34-
<configuration>
35-
<appendAssemblyId>false</appendAssemblyId>
36-
<finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}-distr
37-
</finalName>
38-
<descriptors>
39-
<descriptor>src/assemble/distribution.xml</descriptor>
40-
</descriptors>
41-
</configuration>
42-
</execution>
43-
<execution>
44-
<id>make-bundle</id>
45-
<phase>install</phase>
46-
<goals>
47-
<goal>single</goal>
48-
</goals>
49-
<configuration>
50-
<descriptors>
51-
<descriptor>src/assemble/bundle.xml</descriptor>
52-
</descriptors>
53-
</configuration>
54-
</execution>
55-
</executions>
56-
</plugin>
5723
<plugin>
5824
<groupId>org.apache.maven.plugins</groupId>
5925
<artifactId>maven-surefire-plugin</artifactId>
60-
<version>2.19.1</version>
26+
<version>2.20</version>
6127
<configuration>
6228
<useFile>false</useFile>
6329
<trimStackTrace>false</trimStackTrace>
@@ -172,7 +138,7 @@
172138
<dependency>
173139
<groupId>org.apache.maven.shared</groupId>
174140
<artifactId>maven-verifier</artifactId>
175-
<version>1.5</version>
141+
<version>1.6</version>
176142
<scope>test</scope>
177143
</dependency>
178144
<dependency>
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package com.igormaznitsa.jbbp.mvn.plugin;
2+
3+
import com.igormaznitsa.jbbp.mvn.plugin.converters.Target;
4+
import com.igormaznitsa.meta.annotation.MustNotContainNull;
5+
import org.apache.maven.plugin.AbstractMojo;
6+
import org.apache.maven.plugin.MojoExecutionException;
7+
import org.apache.maven.plugin.MojoFailureException;
8+
import org.apache.maven.plugins.annotations.Parameter;
9+
import org.apache.maven.project.MavenProject;
10+
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
11+
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
12+
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
13+
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
14+
15+
import javax.annotation.Nonnull;
16+
import javax.annotation.Nullable;
17+
import java.io.File;
18+
import java.util.HashSet;
19+
import java.util.Set;
20+
21+
public abstract class AbstractJBBPMojo extends AbstractMojo {
22+
@Parameter(property = "project", required = true, readonly = true)
23+
protected MavenProject project;
24+
25+
/**
26+
* Specifies whether sources are added to the {@code compile} or {@code test}
27+
* scope.
28+
*/
29+
@Parameter(alias = "generateTestSources", defaultValue = "false")
30+
protected boolean generateTestSources;
31+
/**
32+
* Package to override package name extracted from script file name, it will be
33+
* common for all processed classes.
34+
*/
35+
@Parameter(alias = "commonPackage")
36+
protected String commonPackage;
37+
/**
38+
* Target for source generation.
39+
*/
40+
@Parameter(alias = "target", defaultValue = "JAVA_1_6")
41+
protected String target;
42+
/**
43+
* Provides an explicit list of all the JBBP scripts that should be included
44+
* in the generate phase of the plug-in.
45+
* <p>
46+
* A set of Ant-like inclusion patterns used to select files from the source
47+
* directory for processing. By default, the pattern
48+
* <code>**&#47;*.jbbp</code> is used to select JBBP script files.
49+
* </p>
50+
*/
51+
@Parameter(alias = "includes")
52+
protected final Set<String> includes = new HashSet<String>();
53+
/**
54+
* A set of Ant-like exclusion patterns used to prevent certain files from
55+
* being processed. By default, this set is empty such that no files are
56+
* excluded.
57+
*/
58+
@Parameter(alias = "excludes")
59+
protected final Set<String> excludes = new HashSet<String>();
60+
/**
61+
* Flag to skip processing of the plug-in.
62+
*/
63+
@Parameter(alias = "skip", defaultValue = "false")
64+
protected boolean skip;
65+
/**
66+
* Destination directory for generated Java classes, the default value is
67+
* "${project.build.directory}/generated-sources/jbbp"
68+
*/
69+
@Parameter(alias = "outputDirectory", defaultValue = "${project.build.directory}/generated-sources/jbbp")
70+
protected File outputDirectory;
71+
/**
72+
* Flag to make plugin verbose.
73+
*/
74+
@Parameter(alias = "verbose", defaultValue = "false")
75+
protected boolean verbose;
76+
/**
77+
* Source directory for JBBP scripts, the default value is
78+
* "${project.basedir}/src/jbbp"
79+
*/
80+
@Parameter(alias = "sourceDirectory", defaultValue = "${project.basedir}/src/jbbp")
81+
protected File sourceDirectory;
82+
83+
@Nullable
84+
public String getTarget() {
85+
return this.target;
86+
}
87+
88+
public void setTarget(@Nullable final String value) {
89+
this.target = value;
90+
}
91+
92+
@MustNotContainNull
93+
@Nonnull
94+
public Set<String> getExcludes() {
95+
return this.excludes;
96+
}
97+
98+
@Nullable
99+
public String getCommonPackage() {
100+
return this.commonPackage;
101+
}
102+
103+
public void setCommonPackage(@Nullable final String text) {
104+
this.commonPackage = text;
105+
}
106+
107+
@MustNotContainNull
108+
@Nonnull
109+
public Set<String> getIncludes() {
110+
return this.includes;
111+
}
112+
113+
@Nonnull
114+
public File getSourceDirectory() {
115+
return this.sourceDirectory;
116+
}
117+
118+
public void setSourceDirectory(@Nonnull final File file) {
119+
if (file == null) throw new NullPointerException("File must not be null");
120+
this.sourceDirectory = file;
121+
}
122+
123+
public boolean getSkip() {
124+
return this.skip;
125+
}
126+
127+
public void setSkip(final boolean value) {
128+
this.skip = value;
129+
}
130+
131+
@Nonnull
132+
public File getOutputDirectory() {
133+
return this.outputDirectory;
134+
}
135+
136+
public boolean getVerbose() {
137+
return this.verbose;
138+
}
139+
140+
public void setVerbose(final boolean flag) {
141+
this.verbose = flag;
142+
}
143+
144+
public void setGenerateTestSources(final boolean flag) {
145+
this.generateTestSources = flag;
146+
}
147+
148+
public boolean getGenerateTestSources() {
149+
return this.generateTestSources;
150+
}
151+
152+
protected void registerSourceRoot(@Nonnull final File outputDir) {
153+
if (this.generateTestSources) {
154+
getLog().debug("Registering TEST source root : " + outputDir.getPath());
155+
this.project.addTestCompileSourceRoot(outputDir.getPath());
156+
} else {
157+
getLog().debug("Registering source root : " + outputDir.getPath());
158+
this.project.addCompileSourceRoot(outputDir.getPath());
159+
}
160+
}
161+
162+
@Nonnull
163+
public Set<File> findSources(@Nonnull final File targetDirectory) throws MojoExecutionException {
164+
try {
165+
final SourceInclusionScanner scanner = new SimpleSourceInclusionScanner(this.includes, this.excludes);
166+
scanner.addSourceMapping(new SuffixMapping("JBBP", "jbbp"));
167+
return scanner.getIncludedSources(this.sourceDirectory, targetDirectory);
168+
} catch (InclusionScanException ex) {
169+
throw new MojoExecutionException("Error during sources scanning", ex);
170+
}
171+
}
172+
173+
public void logInfo(@Nullable final String text, final boolean onlyIfVerbose) {
174+
if (text != null) {
175+
if (this.verbose) {
176+
getLog().info(text);
177+
} else {
178+
if (!onlyIfVerbose) {
179+
getLog().info(text);
180+
}
181+
}
182+
}
183+
}
184+
185+
public boolean checkSetNonEmptyWithLogging(@Nonnull final Set<File> files) {
186+
boolean result = true;
187+
if (files.isEmpty()) {
188+
getLog().warn("There is not any detected JBBP script");
189+
result = false;
190+
}
191+
return result;
192+
}
193+
194+
@Override
195+
public final void execute() throws MojoExecutionException, MojoFailureException {
196+
if (this.skip) {
197+
logInfo("Skip processing", false);
198+
return;
199+
}
200+
201+
if (this.includes.isEmpty()) {
202+
this.includes.add("**/*.jbbp");
203+
}
204+
205+
executeMojo();
206+
}
207+
208+
@Nonnull
209+
public Target findTarget() throws MojoExecutionException {
210+
final Target theTarget;
211+
try {
212+
return Target.valueOf(this.target);
213+
} catch (IllegalArgumentException ex) {
214+
throw new MojoExecutionException("Unsupported target : " + this.target, ex);
215+
}
216+
}
217+
218+
protected abstract void executeMojo() throws MojoExecutionException, MojoFailureException;
219+
}

0 commit comments

Comments
 (0)