Skip to content

Commit 0053fac

Browse files
committed
refactoring, added clean mojo
1 parent 4184ce5 commit 0053fac

File tree

10 files changed

+213
-170
lines changed

10 files changed

+213
-170
lines changed

jbbp-maven/jbbp-maven-plugin/src/assemble/bundle.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
2-
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
1+
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
3+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
54
<id>bundle</id>
6-
5+
76
<includeBaseDirectory>false</includeBaseDirectory>
87
<includeSiteDirectory>false</includeSiteDirectory>
98

109
<formats>
1110
<format>jar</format>
12-
</formats>
11+
</formats>
1312
<fileSets>
1413
<fileSet>
1514
<directory>${project.build.directory}</directory>
1615
<outputDirectory>/</outputDirectory>
1716
<includes>
18-
<include>*.jar.asc</include>
19-
<include>*.jar</include>
20-
<include>*.pom</include>
21-
<include>*.pom.asc</include>
17+
<include>*.jar.asc</include>
18+
<include>*.jar</include>
19+
<include>*.pom</include>
20+
<include>*.pom.asc</include>
2221
</includes>
2322
<excludes>
24-
<exclude>original*.*</exclude>
25-
<exclude>*.zip</exclude>
23+
<exclude>original*.*</exclude>
24+
<exclude>*.zip</exclude>
2625
</excludes>
2726
</fileSet>
2827
</fileSets>
Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1-
2-
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1+
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
43
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
5-
<id>distr</id>
6-
7-
<includeBaseDirectory>false</includeBaseDirectory>
8-
<includeSiteDirectory>false</includeSiteDirectory>
4+
<id>distr</id>
5+
6+
<includeBaseDirectory>false</includeBaseDirectory>
7+
<includeSiteDirectory>false</includeSiteDirectory>
98

10-
<formats>
11-
<format>tar.gz</format>
12-
</formats>
13-
<fileSets>
14-
<fileSet>
15-
<directory>${project.basedir}</directory>
16-
<outputDirectory>/project</outputDirectory>
17-
<excludes>
18-
<exclude>target/</exclude>
19-
<exclude>texts/</exclude>
20-
<exclude>nbactions.xml</exclude>
21-
<exclude>catalog.xml</exclude>
22-
<exclude>**/.*</exclude>
23-
</excludes>
24-
</fileSet>
25-
<fileSet>
26-
<outputDirectory>/lib</outputDirectory>
27-
<directory>${project.basedir}/target</directory>
28-
<includes>
29-
<include>${project.build.finalName}.jar</include>
30-
</includes>
31-
</fileSet>
32-
<fileSet>
33-
<outputDirectory>/lib</outputDirectory>
34-
<directory>${project.basedir}</directory>
35-
<includes>
36-
<include>pom.xml</include>
37-
</includes>
38-
</fileSet>
39-
<fileSet>
40-
<outputDirectory>/</outputDirectory>
41-
<directory>${basedir}/texts</directory>
42-
<includes>
43-
<include>*.*</include>
44-
</includes>
45-
</fileSet>
46-
</fileSets>
9+
<formats>
10+
<format>tar.gz</format>
11+
</formats>
12+
<fileSets>
13+
<fileSet>
14+
<directory>${project.basedir}</directory>
15+
<outputDirectory>/project</outputDirectory>
16+
<excludes>
17+
<exclude>target/</exclude>
18+
<exclude>texts/</exclude>
19+
<exclude>nbactions.xml</exclude>
20+
<exclude>catalog.xml</exclude>
21+
<exclude>**/.*</exclude>
22+
</excludes>
23+
</fileSet>
24+
<fileSet>
25+
<outputDirectory>/lib</outputDirectory>
26+
<directory>${project.basedir}/target</directory>
27+
<includes>
28+
<include>${project.build.finalName}.jar</include>
29+
</includes>
30+
</fileSet>
31+
<fileSet>
32+
<outputDirectory>/lib</outputDirectory>
33+
<directory>${project.basedir}</directory>
34+
<includes>
35+
<include>pom.xml</include>
36+
</includes>
37+
</fileSet>
38+
<fileSet>
39+
<outputDirectory>/</outputDirectory>
40+
<directory>${basedir}/texts</directory>
41+
<includes>
42+
<include>*.*</include>
43+
</includes>
44+
</fileSet>
45+
</fileSets>
4746
</assembly>

jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/mvn/plugin/AbstractJBBPMojo.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,26 @@
1919
import java.util.Set;
2020

2121
public abstract class AbstractJBBPMojo extends AbstractMojo {
22+
/**
23+
* Provides an explicit list of all the JBBP scripts that should be included
24+
* in the generate phase of the plug-in.
25+
* <p>
26+
* A set of Ant-like inclusion patterns used to select files from the source
27+
* directory for processing. By default, the pattern
28+
* <code>**&#47;*.jbbp</code> is used to select JBBP script files.
29+
* </p>
30+
*/
31+
@Parameter(alias = "includes")
32+
protected final Set<String> includes = new HashSet<String>();
33+
/**
34+
* A set of Ant-like exclusion patterns used to prevent certain files from
35+
* being processed. By default, this set is empty such that no files are
36+
* excluded.
37+
*/
38+
@Parameter(alias = "excludes")
39+
protected final Set<String> excludes = new HashSet<String>();
2240
@Parameter(property = "project", required = true, readonly = true)
2341
protected MavenProject project;
24-
2542
/**
2643
* Specifies whether sources are added to the {@code compile} or {@code test}
2744
* scope.
@@ -39,24 +56,6 @@ public abstract class AbstractJBBPMojo extends AbstractMojo {
3956
*/
4057
@Parameter(alias = "target", defaultValue = "JAVA_1_6")
4158
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>();
6059
/**
6160
* Flag to skip processing of the plug-in.
6261
*/
@@ -141,14 +140,14 @@ public void setVerbose(final boolean flag) {
141140
this.verbose = flag;
142141
}
143142

144-
public void setGenerateTestSources(final boolean flag) {
145-
this.generateTestSources = flag;
146-
}
147-
148143
public boolean getGenerateTestSources() {
149144
return this.generateTestSources;
150145
}
151146

147+
public void setGenerateTestSources(final boolean flag) {
148+
this.generateTestSources = flag;
149+
}
150+
152151
protected void registerSourceRoot(@Nonnull final File outputDir) {
153152
if (this.generateTestSources) {
154153
getLog().debug("Registering TEST source root : " + outputDir.getPath());
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.igormaznitsa.jbbp.mvn.plugin;
2+
3+
import com.igormaznitsa.jbbp.mvn.plugin.converters.Target;
4+
import org.apache.maven.plugin.MojoExecutionException;
5+
import org.apache.maven.plugin.MojoFailureException;
6+
import org.apache.maven.plugins.annotations.LifecyclePhase;
7+
import org.apache.maven.plugins.annotations.Mojo;
8+
9+
import java.io.File;
10+
import java.util.Set;
11+
12+
/**
13+
* The Mojo looks for all java files generated for JBBP scripts and delete them.
14+
*
15+
* @author Igor Maznitsa
16+
*/
17+
@Mojo(name = "clean", defaultPhase = LifecyclePhase.CLEAN, threadSafe = true)
18+
public class JBBPCleanMojo extends AbstractJBBPMojo {
19+
20+
@Override
21+
public void executeMojo() throws MojoExecutionException, MojoFailureException {
22+
final Set<File> scripts = findSources(this.outputDirectory);
23+
if (checkSetNonEmptyWithLogging(scripts)) {
24+
int counter = 0;
25+
final Target target = findTarget();
26+
for (final File aScript : scripts) {
27+
getLog().debug("Processing JBBP script : " + aScript);
28+
final Set<File> files = target.getScriptProcessor().makeTargetFiles(this.getOutputDirectory(), this.getCommonPackage(), aScript);
29+
for (final File f : files) {
30+
if (f.isFile()) {
31+
if (f.delete()) {
32+
counter++;
33+
logInfo("Deleted file '" + f.getAbsolutePath() + "' for script '" + aScript + "'", true);
34+
} else {
35+
getLog().error("Can't delete file '" + f.getAbsolutePath() + "' for script '" + aScript + "'");
36+
}
37+
} else {
38+
getLog().debug("File '" + f.getAbsolutePath() + "' generated for script '" + aScript + "' is not found");
39+
}
40+
}
41+
}
42+
getLog().info(String.format("Deleted %d file(s)", counter));
43+
}
44+
}
45+
}

jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/mvn/plugin/converters/Java16Converter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Collections;
1818
import java.util.Set;
1919

20-
public class Java16Converter implements ScriptProcessor {
20+
public class Java16Converter implements ScriptProcessor {
2121
@Override
2222
public void processScript(
2323
@Nonnull final JBBPGenerateMojo mojo,
@@ -60,6 +60,7 @@ public void processScript(
6060
}
6161

6262
@Override
63+
@Nonnull
6364
public Set<File> makeTargetFiles(@Nullable File targetDir, @Nullable String classPackage, @Nonnull File jbbpScript) {
6465
return Collections.singleton(Utils.scriptFileToJavaFile(targetDir, classPackage, jbbpScript));
6566
}

jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/mvn/plugin/converters/ScriptProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ void processScript(
2020
@Nonnull JBBPCustomFieldTypeProcessor customFieldTypeProcessor
2121
) throws IOException;
2222

23+
@Nonnull
2324
Set<File> makeTargetFiles(@Nullable File targetDir, @Nullable String classPackage, @Nonnull File jbbpScript);
2425
}

jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/mvn/plugin/converters/Target.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.igormaznitsa.jbbp.mvn.plugin.converters;
22

3-
import com.igormaznitsa.jbbp.mvn.plugin.converters.Java16Converter;
4-
import com.igormaznitsa.jbbp.mvn.plugin.converters.ScriptProcessor;
5-
63
import javax.annotation.Nonnull;
74

85
public enum Target {

jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/mvn/plugin/utils/Utils.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public static String getEncoding(@Nullable final String charsetName) {
4242
final Charset defaultCharset = Charset.defaultCharset();
4343
try {
4444
return (charsetName == null) ? defaultCharset.name() : Charset.forName(charsetName.trim()).name();
45-
}catch(IllegalCharsetNameException ex){
46-
throw new IllegalArgumentException("Can't recognoze charset for name '"+charsetName+'\'');
45+
} catch (IllegalCharsetNameException ex) {
46+
throw new IllegalArgumentException("Can't recognoze charset for name '" + charsetName + '\'');
4747
}
4848
}
4949

@@ -75,9 +75,10 @@ public static String extractPackageName(@Nonnull final String fileNameWithoutExt
7575

7676
/**
7777
* Convert script file into path to Java class file.
78-
* @param targetDir the target dir for generated sources, it can be null
78+
*
79+
* @param targetDir the target dir for generated sources, it can be null
7980
* @param classPackage class package to override extracted one from script name, it can be null
80-
* @param scriptFile the script file, must not be null
81+
* @param scriptFile the script file, must not be null
8182
* @return java source file for the script file
8283
*/
8384
@Nonnull
@@ -86,9 +87,9 @@ public static File scriptFileToJavaFile(@Nullable final File targetDir, @Nullabl
8687
final String className = Utils.extractClassName(rawFileName);
8788
final String packageName = classPackage == null ? Utils.extractPackageName(rawFileName) : classPackage;
8889

89-
String fullClassName = packageName.isEmpty() ? className : packageName +'.'+className;
90-
fullClassName = fullClassName.replace('.',File.separatorChar)+".java";
90+
String fullClassName = packageName.isEmpty() ? className : packageName + '.' + className;
91+
fullClassName = fullClassName.replace('.', File.separatorChar) + ".java";
9192

92-
return new File(targetDir,fullClassName);
93+
return new File(targetDir, fullClassName);
9394
}
9495
}

jbbp-maven/jbbp-maven-plugin/src/test/java/com/igormaznitsa/jbbp/mvn/plugin/UtilsTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
*/
1616
package com.igormaznitsa.jbbp.mvn.plugin;
1717

18-
import static org.junit.Assert.*;
19-
2018
import com.igormaznitsa.jbbp.mvn.plugin.utils.Utils;
2119
import org.junit.Test;
2220

21+
import static org.junit.Assert.assertEquals;
22+
2323
public class UtilsTest {
2424

25-
@Test
26-
public void testExtractClassName() {
27-
assertEquals("", Utils.extractClassName(""));
28-
assertEquals("", Utils.extractClassName("a.b.c."));
29-
assertEquals("hello", Utils.extractClassName("hello"));
30-
assertEquals("hello", Utils.extractClassName("a.b.c.hello"));
31-
assertEquals("hello", Utils.extractClassName(".hello"));
32-
}
25+
@Test
26+
public void testExtractClassName() {
27+
assertEquals("", Utils.extractClassName(""));
28+
assertEquals("", Utils.extractClassName("a.b.c."));
29+
assertEquals("hello", Utils.extractClassName("hello"));
30+
assertEquals("hello", Utils.extractClassName("a.b.c.hello"));
31+
assertEquals("hello", Utils.extractClassName(".hello"));
32+
}
3333

34-
@Test
35-
public void testExtractPackageName() {
36-
assertEquals("", Utils.extractPackageName(""));
37-
assertEquals("", Utils.extractPackageName("hello"));
38-
assertEquals("a", Utils.extractPackageName("a.hello"));
39-
assertEquals("a.b.c", Utils.extractPackageName("a.b.c.hello"));
40-
assertEquals("a.b.c", Utils.extractPackageName("a.b.c."));
41-
assertEquals("", Utils.extractPackageName(".hello"));
42-
}
34+
@Test
35+
public void testExtractPackageName() {
36+
assertEquals("", Utils.extractPackageName(""));
37+
assertEquals("", Utils.extractPackageName("hello"));
38+
assertEquals("a", Utils.extractPackageName("a.hello"));
39+
assertEquals("a.b.c", Utils.extractPackageName("a.b.c.hello"));
40+
assertEquals("a.b.c", Utils.extractPackageName("a.b.c."));
41+
assertEquals("", Utils.extractPackageName(".hello"));
42+
}
4343

4444
}

0 commit comments

Comments
 (0)