Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new maven rules #4

Open
wants to merge 82 commits into
base: feature/use-new-maven-rules
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
cf52121
Update README.md
Jun 28, 2018
863e434
Correct the URL of Protocol Buffers
Jun 28, 2018
4834956
Update README.md
Jun 28, 2018
74c247c
Correct typo.
Jun 28, 2018
c749b6e
Update README.md
Jun 28, 2018
e85fb2e
Correct the sample JSON
Jun 28, 2018
0330131
Add white space
Jun 28, 2018
04b571f
Delete the unnecessary command line
Jun 29, 2018
c312f66
Update README.md
Jun 29, 2018
4e8ddc8
Add a sample bash script with 'heredoc'
Jun 29, 2018
540f4d3
Update README.md
Jun 29, 2018
ff5ca8a
Update README.md
Jun 29, 2018
0d6799c
Improve unit tests
Jun 30, 2018
42e3387
Close stream
Jun 30, 2018
9937e1d
Find resources and add to library and test rules
Jun 30, 2018
3f7c0d5
Update for resources of build and test goals
Jun 30, 2018
5442046
Add sample WORKSPACE and BUILD scripts
Jun 30, 2018
bc252a4
Delete LICENSE
Jun 30, 2018
4ecf102
Create LICENSE
Jun 30, 2018
e5cfd0d
Add comment to capture test output
Jun 30, 2018
1fcbe80
Add 'Awesome Bazel'
Jun 30, 2018
643fad5
Update README.md
Jun 30, 2018
f2d1025
If there are no resources, then remove the empty line
Jun 30, 2018
5c942ca
Remove the empty resources line
Jun 30, 2018
16de124
White space
Jun 30, 2018
93c1db9
Update README.md
Jul 1, 2018
0054415
Make file operations more readable
Jul 1, 2018
4a6ab6a
Ignore pom.xml.versionsBackup
Jul 1, 2018
4212d8f
Switch to @BeforeClass and @AfterClass
Jul 1, 2018
9578ad5
Increase plugin version, update httpcore
Jul 1, 2018
4bcf865
Refactor ex -> e
Jul 1, 2018
bf310a8
Make generation of resource list more efficient, may be useful for ma…
Jul 1, 2018
ca6c7a2
Correct Optional usage
Jul 2, 2018
f6c5984
Refactored for better readability
Jul 2, 2018
b4b53e2
White space
Jul 2, 2018
95e94bb
Sanitize test and binary names
Jul 3, 2018
8b32778
Increase version
Jul 3, 2018
5520cfd
Switch to sanitized test and binary names, correct Bazel commands
Jul 3, 2018
7095c2b
Correct prompt
Jul 3, 2018
3950fd8
Remove HEREDOC, use plain cat
Jul 3, 2018
a911348
Switch back to HEREDOC
Jul 3, 2018
b270926
Add prompt
Jul 3, 2018
f872461
White space
Jul 3, 2018
cf8e26d
Correct chmod
Jul 3, 2018
2586a55
Update README.md
Jul 3, 2018
b18d281
Move main_class up
Jul 3, 2018
59e1d2f
Increase version
Jul 3, 2018
a96d2b0
Move main_class up
Jul 3, 2018
1299ae9
Update README.md
Jul 3, 2018
6a44fe9
Mark XML code
Jul 4, 2018
d6b8286
Improve link on OSGi bundle generation
Jul 4, 2018
e5673f4
Update README.md
Jul 4, 2018
47113a8
Update README.md
Jul 4, 2018
3f8476d
Update with new sections for a better narrative
Jul 5, 2018
c8855a3
Update README.md
Jul 5, 2018
6f8fcfe
Protected is good enough
Jul 7, 2018
62eb403
Improve test quality
Jul 7, 2018
af44b59
White space
OrhanKupusoglu Jul 24, 2018
e2f36fb
White space
OrhanKupusoglu Aug 1, 2018
7616c44
Add info on strict dependencies
OrhanKupusoglu Oct 25, 2018
4534947
Clean before build
OrhanKupusoglu Oct 25, 2018
9db742a
Improve the bazelize script
OrhanKupusoglu Oct 26, 2018
66ecda7
Add example repository quicksort-duplicates
OrhanKupusoglu Oct 26, 2018
4e49bea
Overhaul the goal parameters and update the README.md
OrhanKupusoglu Nov 4, 2018
a4276a9
Use HTML tables instead of MD tables
OrhanKupusoglu Nov 4, 2018
838baa1
Revert back to MD tables
OrhanKupusoglu Nov 4, 2018
7113612
Mention plugin documentation generation
OrhanKupusoglu Nov 5, 2018
f8c2fb9
Add description to parameters and update the README.md
OrhanKupusoglu Nov 6, 2018
1997241
Delete bazelize.out, bazelize.out.html
OrhanKupusoglu Nov 6, 2018
ce2e8a6
Change wording to 'parameter'
OrhanKupusoglu Nov 6, 2018
99d0a63
Remove the experimental multi-thread support
OrhanKupusoglu Nov 20, 2018
10d24c1
Refactor and review the code, remove duplicates
OrhanKupusoglu Nov 21, 2018
c29ba99
Use LifeCycle events better
OrhanKupusoglu Nov 21, 2018
6e755bb
Review the JavaDoc comments
OrhanKupusoglu Nov 21, 2018
4fc19bc
Correct typo
OrhanKupusoglu Nov 21, 2018
64730d3
Add SLOC data
orhan-kupusoglu Dec 5, 2018
3a44083
Correct typo
OrhanKupusoglu Dec 19, 2018
ece20b1
Server names are now valid for Bazel version 0.29.0
steve-hb Sep 2, 2019
db4af3e
Implemented usage of the new maven rules for Bazel
steve-hb Sep 2, 2019
c76a9e8
Moved boilerplate to an extra file
steve-hb Sep 4, 2019
fac56e8
Use the new rules defining the maven repositories; Formatting & cleanup
steve-hb Sep 5, 2019
e366cca
Use recursive globs instead of referencing dozens of classes
steve-hb Sep 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/target/
/target
/bazel*
.idea
_*
tmp-bzl-*.json
BUILD*
WORKSPACE*
pom-effective.xml
pom.xml.versionsBackup
_*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2018 Orhan Kupusoglu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
482 changes: 383 additions & 99 deletions README.md

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<!-- The Basics -->
<groupId>kupusoglu.orhan</groupId>
<artifactId>bazelize-maven-plugin</artifactId>
<version>0.2.1</version>
<version>0.3.3</version>
<packaging>maven-plugin</packaging>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.5.4</version>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand All @@ -24,12 +24,12 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.4</version>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5.2</version>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -46,12 +46,12 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
<version>27.0.1-jre</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
<version>20180813</version>
</dependency>
</dependencies>

Expand All @@ -66,7 +66,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
Expand Down Expand Up @@ -167,7 +167,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.9</version>
<version>4.4.10</version>
</dependency>
</dependencies>
</plugin>
Expand All @@ -176,6 +176,11 @@

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,42 @@ public class GoalBinary extends AbstractMojo {
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

/**
* if true back up the 'BUILD' file
* @parameter
*/
@Parameter(property = "backup", defaultValue = "false")
private Boolean backup;

/**
* if empty set current timestamp as suffix
* @parameter
*/
@Parameter(property = "suffix", defaultValue = "")
private String suffix;

/**
* if empty use name of the main class as rule's name
* @parameter
*/
@Parameter(property = "binName", defaultValue = "")
private String binName;

@Parameter(property = "mainClass", defaultValue = "")
/**
* name of the main class
* @parameter
*/
@Parameter(property = "mainClass", required = true)
private String mainClass;


public void execute() throws MojoExecutionException {
if (project.isExecutionRoot()) {
String finalSuffix = null;
String ctxSuffix = (String)project.getContextValue("suffix");

if (backup) {
LocalDateTime localDateTime = LocalDateTime.now();

if (suffix == null || suffix.isEmpty()) {
finalSuffix = Common.getFormattedTimestamp(localDateTime);
} else {
finalSuffix = suffix;
}
finalSuffix = Common.getBackupSuffix(suffix, ctxSuffix);
}

if (mainClass == null || mainClass.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,76 @@ public class GoalBuild extends AbstractMojo {
@Parameter(defaultValue = "${settings}", required = true, readonly = true)
private Settings settings;

/**
* path of the settings file relative to local repo
* @parameter
*/
@Parameter(property = "settingsFile", defaultValue = "../settings.xml")
private String settingsFile;

@Parameter(property = "rootDir", defaultValue = ".")
private String rootDir;

/**
* if true back up the 'BUILD' files
* @parameter
*/
@Parameter(property = "backup", defaultValue = "true")
private Boolean backup;

/**
* if empty set current timestamp as suffix
* @parameter
*/
@Parameter(property = "suffix", defaultValue = "")
private String suffix;

/**
* add dependency to the black list to be ignored
* @parameter
*/
@Parameter(property = "blackListPattern", defaultValue = "^jdk_tools")
private String blackListPattern;

/**
* default remote repository
* @parameter
*/
@Parameter(property = "defaultServer", defaultValue = "central")
private String defaultServer;

/**
* set scope of the Maven dependency
* @parameter
*/
@Parameter(property = "addScope", defaultValue = "true")
private Boolean addScope;

/**
* add hash of the Maven dependency
* @parameter
*/
@Parameter(property = "addHash", defaultValue = "false")
private Boolean addHash;

@Parameter(property = "addServer", defaultValue = "true")
/**
* add remote server of the Maven dependency
* @parameter
*/
@Parameter(property = "addServer", defaultValue = "false")
private Boolean addServer;

/**
* path of the resource files
* @parameter
*/
@Parameter(property = "resMain", defaultValue = "src/main/resources")
private String resMain;

/**
* use glob("src/main/java/**\/*.java") and glob("src/main/resources/**\/*")
* @parameter
*/
@Parameter(property = "useMavenStructure", defaultValue = "true")
private Boolean useMavenStructure;

private SortedSet<MavenDependency> allDependencies = new TreeSet<>();
private SortedSet<MavenServer> allServers = new TreeSet<>();
private LocalDateTime dateTime = LocalDateTime.now();
Expand All @@ -95,25 +138,23 @@ public class GoalBuild extends AbstractMojo {
public void execute() throws MojoExecutionException {
// for LifeCycle.afterSessionEnd()
if (Common.getProjectData("suffix") == null) { //project.isExecutionRoot()) {
project.setContextValue("rootDir", rootDir);
project.setContextValue("rootDir", project.getBasedir().getAbsolutePath());
project.setContextValue("backup", backup);
project.setContextValue("log", getLog());

LocalDateTime localDateTime = LocalDateTime.now();
String finalSuffix = null;
String ctxSuffix = (String)project.getContextValue("suffix");

if (suffix == null || suffix.isEmpty()) {
finalSuffix = Common.getFormattedTimestamp(localDateTime);
} else {
finalSuffix = suffix;
if (backup) {
finalSuffix = Common.getBackupSuffix(suffix, ctxSuffix);
}

// for BUILD files
Common.setProjectData("suffix", finalSuffix);
// for WORKSPACE file
project.setContextValue("suffix", finalSuffix);

getLog().info("local datetime: " + localDateTime + " | suffix: " + finalSuffix);
getLog().info("suffix: " + finalSuffix);
}

SortedSet<String> removeDep = new TreeSet<>();
Expand Down Expand Up @@ -177,13 +218,12 @@ public void execute() throws MojoExecutionException {
+ Common.getSepSanitize()
+ project.getVersion());

if (rootDir.isEmpty()) {
getLog().info("reading from class resources: " + Common.OUTPUT_FILES.JSON_META);
} else {
Common.setProjectData("rootDir", rootDir);
getLog().info("reading from root directory: "
+ Paths.get(rootDir, Common.OUTPUT_FILES.JSON_META.toString()).normalize().toAbsolutePath());
}

String baseDir = project.getBasedir().getAbsolutePath();
Common.setProjectData("baseDir", baseDir);

getLog().info("reading from root directory: "
+ Paths.get(baseDir, Common.OUTPUT_FILES.JSON_META.toString()).normalize().toAbsolutePath());

Common.setBlackListPattern(finalBlackListPattern);

Expand Down Expand Up @@ -275,6 +315,12 @@ public void execute() throws MojoExecutionException {

String contentLibrary = Common.getTemplateLibrary();

String resFiles;
if (this.useMavenStructure)
resFiles = "glob([\"src/main/resources/**/*\"])";
else
resFiles = "[" + Common.getResources(resMain) + "]";

StringBuilder jsonDependency = new StringBuilder();
StringBuilder jsonServer = new StringBuilder();

Expand All @@ -297,10 +343,10 @@ public void execute() throws MojoExecutionException {

for (MavenDependency dep : allDependencies) {
String depName = Common.sanitize(dep.getGroupId()
+ Common.getSepSanitize()
+ dep.getArtifactId()
+ Common.getSepSanitize()
+ dep.getVersion());
+ Common.getSepSanitize()
+ dep.getArtifactId()
+ Common.getSepSanitize()
+ dep.getVersion());

if (!Common.isBlackListed(depName)) {
JSONObject jsonObject = new JSONObject(dep);
Expand All @@ -313,9 +359,9 @@ public void execute() throws MojoExecutionException {
if (currDep == null || currDep.getLabel().isEmpty()) {
if (!removeDep.contains("@" + dep.getName() + "//jar")) {
build.append(Common.getIndentTwo());
build.append("\"@");
build.append(dep.getName());
build.append("//jar\",");
build.append("\"@maven//:");
build.append(Common.sanitize(dep.getMavenDependencyString(false, false).replaceAll(":", "_")));
build.append("\",");
build.append("\n");
}
} else {
Expand Down Expand Up @@ -346,7 +392,11 @@ public void execute() throws MojoExecutionException {
buildWriter.append(contentLibrary.replaceFirst("#LIB_NAME#",
libName)
.replaceFirst("#SRCS_GLOB#",
Common.getGlobSources(metaDep.getSources()))
this.useMavenStructure ?
"glob([\"src/main/java/**/*.java\"])" :
Common.getGlobSources(metaDep.getSources()))
.replaceFirst("#RESOURCES#",
resFiles)
.replaceFirst("#JAVA_DEPS#",
Common.removeLastChars(build.toString(), 1)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class GoalClean extends AbstractMojo {
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

/**
* delete all generated files including BUILD and WORKSPACE files
* @parameter
*/
@Parameter(property = "expunge", defaultValue = "false")
private Boolean expunge;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,28 @@ public class GoalMeta extends AbstractMojo {
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

/**
* if true back up the 'tmp-bzl-meta.json' files
* @parameter
*/
@Parameter(property = "backup", defaultValue = "false")
private Boolean backup;

/**
* if empty set current timestamp as suffix
* @parameter
*/
@Parameter(property = "suffix", defaultValue = "")
private String suffix;


public void execute() throws MojoExecutionException {
if (project.isExecutionRoot()) {
String finalSuffix = null;
String ctxSuffix = (String)project.getContextValue("suffix");

if (backup) {
LocalDateTime localDateTime = LocalDateTime.now();

if (suffix == null || suffix.isEmpty()) {
finalSuffix = Common.getFormattedTimestamp(localDateTime);
} else {
finalSuffix = suffix;
}
finalSuffix = Common.getBackupSuffix(suffix, ctxSuffix);
}

try {
Expand Down
Loading