mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
add the basis for bulk candy publishing
This commit is contained in:
parent
5fd1f98f6f
commit
83d69823a8
@ -181,6 +181,11 @@
|
|||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.cincheo</groupId>
|
||||||
|
<artifactId>file-visitor</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.martiansoftware</groupId>
|
<groupId>com.martiansoftware</groupId>
|
||||||
<artifactId>jsap</artifactId>
|
<artifactId>jsap</artifactId>
|
||||||
|
|||||||
27
candy-generator/src/main/java/org/jsweet/publisher/Main.java
Normal file
27
candy-generator/src/main/java/org/jsweet/publisher/Main.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.jsweet.publisher;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.jsweet.publisher.visitor.UpdateVersion;
|
||||||
|
|
||||||
|
// THIS IS WIP. One day we will have a really automatized publisher for the JSweet Candies Github organization...
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static String MAVEN_CMD = "/usr/local/bin/mvn";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
File f = new File("/Users/renaudpawlak/git/candies");
|
||||||
|
if (f.exists()) {
|
||||||
|
// FileVisitor[] fileVisitors = new FileVisitor[] {
|
||||||
|
// /*new UpdateFileVisitor(), */new RemoveExtFileVisitor(), new
|
||||||
|
// CommitFileVisitor() };
|
||||||
|
// FileVisitor[] fileVisitors = new FileVisitor[] { new
|
||||||
|
// UpdateVersion("20170726", "rc1") };
|
||||||
|
// FileVisitor[] fileVisitors = new FileVisitor[] { new MvnDeploy()
|
||||||
|
// };
|
||||||
|
FileVisitor.scan(f, new UpdateVersion("20170726", "rc1"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
|
||||||
|
public class GitCommitPush implements FileVisitor {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int errorCount = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Committing projects === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
// System.out.println("visiting: " + file);
|
||||||
|
if (file.isDirectory() && new File(file, ".git").exists()) {
|
||||||
|
System.out.println();
|
||||||
|
System.out.println(file + ": committing git project...");
|
||||||
|
ProcessUtil.runCommand("git", file, false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
count++;
|
||||||
|
System.out.println(file + ": pushing git project...");
|
||||||
|
ProcessUtil.runCommand("git", file, false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p2) -> {
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot push project!");
|
||||||
|
errorCount++;
|
||||||
|
}, "push", "origin", "master");
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot commit project!");
|
||||||
|
errorCount++;
|
||||||
|
}, "commit", "-m", "publishing");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== " + count + " git project(s) updated successfully, " + errorCount + " error(s) ===");
|
||||||
|
System.out.println();
|
||||||
|
return errorCount == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
|
||||||
|
public class GitPull implements FileVisitor {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int errorCount = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Updating projects === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
// System.out.println("visiting: " + file);
|
||||||
|
if (file.isDirectory() && new File(file, ".git").exists()) {
|
||||||
|
System.out.println();
|
||||||
|
System.out.println(file + ": cleaning git project...");
|
||||||
|
ProcessUtil.runCommand("git", file, false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p) -> {
|
||||||
|
count++;
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot clean project!");
|
||||||
|
errorCount++;
|
||||||
|
}, "clean", "-f", "-d");
|
||||||
|
System.out.println(file + ": updating git project...");
|
||||||
|
ProcessUtil.runCommand("git", file, false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p) -> {
|
||||||
|
count++;
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot pull project!");
|
||||||
|
errorCount++;
|
||||||
|
}, "pull", "origin", "master");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== " + count + " git project(s) updated successfully, " + errorCount + " error(s) ===");
|
||||||
|
System.out.println();
|
||||||
|
return errorCount == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
import org.jsweet.publisher.Main;
|
||||||
|
|
||||||
|
public class MvnClean implements FileVisitor {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Clean === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
// System.out.println("visiting: " + file);
|
||||||
|
if (file.isFile() && file.getName().equals("pom.xml")) {
|
||||||
|
|
||||||
|
ProcessUtil.runCommand(Main.MAVEN_CMD, file.getParentFile(), false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot clean Maven directory");
|
||||||
|
}, "clean");
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== Cleaned " + count + " project(s) ===");
|
||||||
|
System.out.println();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
import org.jsweet.publisher.Main;
|
||||||
|
|
||||||
|
public class MvnDeploy implements FileVisitor {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int errorCount = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Deploy === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
// System.out.println("visiting: " + file);
|
||||||
|
if (file.isFile() && file.getName().equals("pom.xml")) {
|
||||||
|
|
||||||
|
ProcessUtil.runCommand("rm", file.getParentFile(), false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot clean resources");
|
||||||
|
}, "-rf", "src/main/resources/META-INF/resources");
|
||||||
|
|
||||||
|
ProcessUtil.runCommand(Main.MAVEN_CMD, file.getParentFile(), false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
count++;
|
||||||
|
}, () -> {
|
||||||
|
errorCount++;
|
||||||
|
System.out.println("ERROR: cannot deploy");
|
||||||
|
}, "clean", "deploy");
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== Deployed " + count + " project(s), " + errorCount + " error(s) ===");
|
||||||
|
System.out.println();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
|
||||||
|
public class RemoveExt implements FileVisitor {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Removing ext in group id === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
//System.out.println("visiting: " + file);
|
||||||
|
if (file.isFile() && file.getName().equals("pom.xml")) {
|
||||||
|
String content = FileUtils.readFileToString(file);
|
||||||
|
if (content.contains("<groupId>org.jsweet.candies.ext</groupId>")) {
|
||||||
|
System.out.println(file+": removing ext in group");
|
||||||
|
content = content.replace("<groupId>org.jsweet.candies.ext</groupId>",
|
||||||
|
"<groupId>org.jsweet.candies</groupId>");
|
||||||
|
FileUtils.writeStringToFile(file, content);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
ProcessUtil.runCommand("git", file.getParentFile(), false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot add file");
|
||||||
|
}, "add", file.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== Removed " + count + " ext ===");
|
||||||
|
System.out.println();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package org.jsweet.publisher.visitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.cincheo.filevisitor.FileVisitor;
|
||||||
|
import org.cincheo.filevisitor.ProcessUtil;
|
||||||
|
|
||||||
|
public class UpdateVersion implements FileVisitor {
|
||||||
|
|
||||||
|
String version;
|
||||||
|
String transpilerVersion;
|
||||||
|
|
||||||
|
Pattern artifactVersionPattern = Pattern.compile("(<version>\\d*.\\d*.\\d*-)(\\w*)(</version>\\s*<properties>)");
|
||||||
|
Pattern versionPattern = Pattern.compile("(<version>\\d*.\\d*.\\d*-)(\\w*)(</version>)");
|
||||||
|
Pattern coreVersionPattern = Pattern.compile("(<version>\\d*-)(\\w*)(</version>)");
|
||||||
|
Pattern transpilerVersionPattern = Pattern
|
||||||
|
.compile("(<artifactId>jsweet-maven-plugin</artifactId>\\s*<version>\\d*.\\d*.\\d*-)(\\w*)(</version>)");
|
||||||
|
|
||||||
|
public UpdateVersion(String version, String transpilerVersion) {
|
||||||
|
this.version = version;
|
||||||
|
this.transpilerVersion = transpilerVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBegin() {
|
||||||
|
System.out.println("=== Updating version === ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(File file) {
|
||||||
|
try {
|
||||||
|
// System.out.println("visiting: " + file);
|
||||||
|
if (file.isFile() && file.getName().equals("pom.xml")) {
|
||||||
|
System.out.println("update version: " + file);
|
||||||
|
String content = FileUtils.readFileToString(file);
|
||||||
|
Matcher m = artifactVersionPattern.matcher(content);
|
||||||
|
if (!m.find()) {
|
||||||
|
throw new RuntimeException("wrong version");
|
||||||
|
}
|
||||||
|
m = versionPattern.matcher(content);
|
||||||
|
content = m.replaceAll("$1" + version + "$3");
|
||||||
|
m = coreVersionPattern.matcher(content);
|
||||||
|
content = m.replaceAll("$1" + version + "$3");
|
||||||
|
m = transpilerVersionPattern.matcher(content);
|
||||||
|
content = m.replaceAll("$1" + transpilerVersion + "$3");
|
||||||
|
FileUtils.writeStringToFile(file, content);
|
||||||
|
count++;
|
||||||
|
|
||||||
|
ProcessUtil.runCommand("git", file.getParentFile(), false, (out) -> {
|
||||||
|
System.out.println(out);
|
||||||
|
}, (p1) -> {
|
||||||
|
}, () -> {
|
||||||
|
System.out.println("ERROR: cannot add file");
|
||||||
|
}, "add", file.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onEnd() {
|
||||||
|
System.out.println("=== Updated " + count + " project versions ===");
|
||||||
|
System.out.println();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* Contains all the visitors for publishing the candies.
|
||||||
|
*
|
||||||
|
* @author Renaud Pawlak
|
||||||
|
*/
|
||||||
|
package org.jsweet.publisher.visitor;
|
||||||
Loading…
x
Reference in New Issue
Block a user