Skip to content
This repository has been archived by the owner on Jun 25, 2018. It is now read-only.

Commit

Permalink
Large Refactoring: Splitted up maven and ivy generators from cmvn pro…
Browse files Browse the repository at this point in the history
…ject. Better internal state and initialization logic. Fixed bug loosing configured state in some situations.
  • Loading branch information
lefou committed Feb 5, 2011
1 parent 160a4c7 commit b61b87a
Show file tree
Hide file tree
Showing 18 changed files with 625 additions and 510 deletions.
2 changes: 1 addition & 1 deletion de.tototec.tools.cmvn-executable/cmvn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ plugin: org.apache.felix:maven-bundle-plugin:2.0.1; \
<Bundle-RequiredExecutionEnvironment>JavaSE-1.6</Bundle-RequiredExecutionEnvironment> \
<Conditional-Package>*</Conditional-Package> \
<Embed-Dependency>de.tototec.tools.cmvn\;inline=true</Embed-Dependency> \
<Main-Class>de.tototec.tools.cmvn.Cmvn</Main-Class>
<Main-Class>de.tototec.tools.cmvn.CmvnApp</Main-Class>
2 changes: 2 additions & 0 deletions de.tototec.tools.cmvn/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<classpathentry kind="src" output="target/classes" path="target/generated-sources/xmlbeans"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="target/generated-classes/xmlbeans"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" path="src/main/scala"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 6 additions & 0 deletions de.tototec.tools.cmvn/.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
Expand All @@ -20,5 +25,6 @@
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
</natures>
</projectDescription>
4 changes: 3 additions & 1 deletion de.tototec.tools.cmvn/cmvn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ plugin: org.apache.felix:maven-bundle-plugin:2.0.1; \
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> \
<Bundle-RequiredExecutionEnvironment>JavaSE-1.6</Bundle-RequiredExecutionEnvironment> \
<Conditional-Package>de.tobiasroeser.cmdoption.*</Conditional-Package> \
<Main-Class>de.tototec.tools.cmvn.Cmvn</Main-Class>
<Main-Class>de.tototec.tools.cmvn.CmvnApp</Main-Class>

# required >=cmvn-0.1.1
-configClass: dir=src/main/java;className=de.tototec.tools.cmvn.Config;cmvnVersion=$${CMVN_VERSION}

repo: http://scala-tools.org/repo-releases
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import de.tobiasroeser.cmdoption.GroupConstraintType;
import de.tobiasroeser.cmdoption.GroupConstraints;

public class Cmvn {
public class CmvnApp {

/**
* Single argument processor that can provide its successor (for the next
Expand Down Expand Up @@ -57,7 +57,7 @@ public static class CmdlineOptions {

public static void main(final String[] args) {
try {
new Cmvn().run(args);
new CmvnApp().run(args);
} catch (final RuntimeException e) {
System.out.println("*** cmvn exited abnormally. Please check the exception details below. ***");
e.printStackTrace(System.out);
Expand Down Expand Up @@ -94,22 +94,22 @@ public void run(final String[] args) {

// Default Mode: run maven
boolean runMaven = false;
boolean reconfigure = false;
boolean regenerate = false;

// Clean Mode
boolean runClean = false;
boolean runDistClean = false;

// Configure mode
boolean runGenerate = false;
boolean runConfigure = false;
boolean forceGenerate = false;
boolean autoReconfigure = false;
final String[] mavenSettingsFile = new String[1];
final String[] mavenRepoDir = new String[1];
final String[] mavenBin = new String[1];

// Experimental
boolean runGenerateIvyFiles = false;
boolean generateIvyFiles = false;
boolean forceSystemScope = false;

NextArgAction nextArgAction = null;
Expand Down Expand Up @@ -139,25 +139,25 @@ public void run(final String[] args) {
} else if (arg.equals("--build")) {
runMaven = true;
} else if (arg.equals("--clean")) {
runGenerate = false;
runConfigure = false;
runMaven = false;
runClean = true;
} else if (arg.equals("--distclean")) {
runGenerate = false;
runConfigure = false;
runMaven = false;
runDistClean = true;
} else if (arg.equals("--force")) {
forceGenerate = true;
} else if (arg.equals("--configure")) {
runGenerate = true;
runConfigure = true;
forceGenerate = true;
runMaven = false;
} else if (arg.equals("--auto-regenerate") || arg.equals("--auto-reconfigure")) {
autoReconfigure = true;
} else if (arg.equals("--regenerate") || arg.equals("--reconfigure")) {
reconfigure = true;
regenerate = true;
} else if (arg.equals("--generate-ivy")) {
runGenerateIvyFiles = true;
generateIvyFiles = true;
} else if (arg.equals("--build")) {
runMaven = true;
} else if (arg.equals("--force-system-scope")) {
Expand Down Expand Up @@ -192,7 +192,7 @@ public NextArgAction processArg(final String arg) {
}

int modeCount = 0;
for (final boolean flag : new Boolean[] { runGenerate, reconfigure, runMaven }) {
for (final boolean flag : new Boolean[] { runConfigure, regenerate, runMaven }) {
if (flag) {
++modeCount;
}
Expand All @@ -201,19 +201,20 @@ public NextArgAction processArg(final String arg) {
throw new RuntimeException("Only one mode can be selected.");
}

if (runGenerate && !mavenArgs.isEmpty()) {
if (runConfigure && !mavenArgs.isEmpty()) {
throw new RuntimeException("Invalid arguments in --configure mode: " + mavenArgs);
}

final MavenProject project = new MavenProject(new File(System.getProperty("user.dir")));
final CmvnProject project = new CmvnProject(new File(System.getProperty("user.dir")));

final boolean upToDate = project.isUpToDateRecursive();
System.out.println("Project up-to-date: " + upToDate);

// System.out.println(project);

if (modeCount == 0 && mavenArgs.isEmpty() && project.getMavenConfig() != null
&& project.getMavenConfig().isAutoReconfigure()) {
reconfigure = true;
if (modeCount == 0 && mavenArgs.isEmpty() && project.getConfiguredState() != null
&& project.getConfiguredState().isAutoReconfigure()) {
regenerate = true;
modeCount = 1;
}

Expand All @@ -232,39 +233,41 @@ public NextArgAction processArg(final String arg) {
project.cleanGeneratedFilesRecursive();
}

if (!upToDate && runMaven && !runGenerate) {
if (project.getMavenConfig() != null && project.getMavenConfig().isAutoReconfigure()) {
reconfigure = true;
if (!upToDate && runMaven && !runConfigure) {
if (project.getConfiguredState() != null && project.getConfiguredState().isAutoReconfigure()) {
regenerate = true;
} else {
throw new RuntimeException(
"Projects are not up-to-date. Please run with '--configure' or '--reconfigure' option.");
}
}

if (reconfigure) {
if (regenerate) {
if (!upToDate || forceGenerate) {
System.out.println("Reconfiguring...");

final MavenConfig mavenConfig = project.getMavenConfig();
if (mavenConfig == null || mavenConfig.getRootProjectFile() == null) {
throw new RuntimeException("Cannot reconfigure. Not enough information (unknown root project)");
}

final String rootProjectFile = mavenConfig.getRootProjectFile();
final MavenProject rootProject = new MavenProject(new File(rootProjectFile));
// second param is null, we wont change to current state
final ConfigureRequest configureRequest = new ConfigureRequest(true);
configureRequest.setForce(forceGenerate);
rootProject.generateMavenProjectRecursive(configureRequest);
// final CmvnConfig mavenConfig = project.getMavenConfig();
// if (mavenConfig == null || mavenConfig.getRootProjectFile()
// == null) {
// throw new
// RuntimeException("Cannot reconfigure. Not enough information (unknown root project)");
// }
//
// final String rootProjectFile =
// mavenConfig.getRootProjectFile();
// final CmvnProject rootProject = new CmvnProject(new
// File(rootProjectFile));

project.generateProjectRecursive(!forceGenerate);
}
}

if (runGenerate) {
if (runConfigure) {
System.out.println("Generating (if needed)...");
final ConfigureRequest configureRequest = new ConfigureRequest(false);
final ConfigureRequest configureRequest = new ConfigureRequest();
configureRequest.setForce(true);
configureRequest.setAutoReconfigure(autoReconfigure);
configureRequest.setGenerateIvy(runGenerateIvyFiles);
configureRequest.setGenerateIvy(generateIvyFiles);
if (mavenSettingsFile[0] != null) {
File file = new File(mavenSettingsFile[0]);
if (!file.isAbsolute()) {
Expand All @@ -287,26 +290,37 @@ public NextArgAction processArg(final String arg) {
configureRequest.setMavenExecutable(file.getPath());
}
configureRequest.setForceSystemScope(forceSystemScope);
project.generateMavenProjectRecursive(configureRequest);
project.configureProjectRecursive(configureRequest);
}

if (runMaven) {
System.out.println("Running Maven...");
final MavenConfig usedMavenConfig = project.getMavenConfig();
final CmvnConfiguredState configuredState = project.getConfiguredState();
if (configuredState == null) {
throw new RuntimeException("Could not access configured cmvn state.");
}
final LinkedList<String> mvnArgs = new LinkedList<String>(mavenArgs);
if (usedMavenConfig.getMavenExecutable() != null) {
mvnArgs.add(0, usedMavenConfig.getMavenExecutable());
if (configuredState.getMavenExecutable() != null) {
mvnArgs.add(0, configuredState.getMavenExecutable());
} else {
mvnArgs.add(0, "mvn");
}
mvnArgs.add(1, "-s");
mvnArgs.add(2, usedMavenConfig.getSettingsFile());
mvnArgs.add(2, configuredState.getSettingsFile());

// if(configuredState.getLocalRepository() != null) {
// mvnArgs.add();
// }

final ProcessBuilder pB = new ProcessBuilder(mvnArgs);
Process process = null;
Thread outThread = null;
try {
System.out.println("Using Maven settings file: " + usedMavenConfig.getSettingsFile());
System.out.println("Using local Maven repository: " + usedMavenConfig.getLocalRepository());
System.out.println("Using Maven settings file: " + configuredState.getSettingsFile());
// if (configuredState.getLocalRepository() != null) {
// System.out.println("Using local Maven repository: " +
// configuredState.getLocalRepository());
// }
System.out.println("Executing " + mvnArgs + "...");
process = pB.start();
copyInBackgroundThread(process.getErrorStream(), System.err);
Expand Down Expand Up @@ -367,6 +381,7 @@ private void printUsage() {
help += " --distclean Enables DISTCLEAN mode\n";
help += "\n";
help += "Options for CONFIGURE mode:\n";
help += " --auto-regenerate (Deprecated) Same as --auto-reconfigure\n";
help += " --auto-reconfigure Enable automatic reconfiguration for out-of-date files\n";
help += " --force Configure and generate all files\n";
help += " --maven-repo DIR Use the given (existing) directory DIR as local Maven repository\n";
Expand All @@ -376,7 +391,8 @@ private void printUsage() {
help += " --force-system-scope Forces all dependencies to be of system scope (in pom.xml)\n";
help += "\n";
help += "Options for BUILD mode:\n";
help += " --reconfigure Automatically reconfigure if some source files are out-of-date\n";
help += " --regenerate Automatically reconfigure if some source files are out-of-date\n";
help += " --reconfigure (Deprecated) Same as --regenerate\n";
help += "\n";
System.out.println(help);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import de.tototec.tools.cmvn.model.Dependency;
import de.tototec.tools.cmvn.model.Module;
import de.tototec.tools.cmvn.model.Plugin;
import de.tototec.tools.cmvn.model.ProjectConfig;
import de.tototec.tools.cmvn.model.CmvnProjectConfig;
import de.tototec.tools.cmvn.model.Repository;

public enum CmvnConfigKey implements ProjectConfigKeyValueReader {

PROJECT("project") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {
final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue, ";", "=", "true");
final String[] split = withOptions.getValue().split(":", 3);
if (split.length < 3) {
Expand All @@ -41,7 +41,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

DEPENDENCY("dependency", "compile", "test", "runtime", "system", "dependencyManagement") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {

final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue, ";", "=", "true");

Expand Down Expand Up @@ -87,7 +87,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

PROPERTY("property") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {
final String[] split = keyValue.getValue().split("=", 2);
if (split.length == 2) {
projectConfig.getProperties().put(split[0].trim(), split[1].trim());
Expand All @@ -99,7 +99,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

REPOSITORY("repository", "repo", "pluginrepo", "artifactrepo") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {

final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue, ";", "=", "true");

Expand Down Expand Up @@ -132,7 +132,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

MODULE("module") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {

final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue, ";", "=", "true");
final Module module = new Module(withOptions.getValue());
Expand All @@ -153,7 +153,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

PLUGIN("plugin") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {
final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue, ";", "=", "true");

final String[] split = withOptions.getValue().split(":", 3);
Expand Down Expand Up @@ -189,7 +189,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

BUILD("build") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {
// We only have options, so we start the value with an ";"
final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue.getKey(), ";"
+ keyValue.getValue(), ";", "=", "true");
Expand All @@ -209,7 +209,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

VARIABLE("-val") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {

final String[] split = keyValue.getValue().split("=", 2);
if (split.length != 2) {
Expand All @@ -229,7 +229,7 @@ public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {

CONFIG_CLASS("-configClass") {
@Override
public void read(final ProjectConfig projectConfig, final KeyValue keyValue) {
public void read(final CmvnProjectConfig projectConfig, final KeyValue keyValue) {
// We only have options, so we start the value with an ";"
final KeyValueWithOptions withOptions = new KeyValueWithOptions(keyValue.getKey(), ";"
+ keyValue.getValue(), ";", "=", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

@Data
public class MavenConfig {
public class CmvnConfiguredState {
private boolean controlSettingsFile;
private boolean controlRepoDir;
private String localRepository;
Expand All @@ -12,4 +12,5 @@ public class MavenConfig {
private boolean autoReconfigure;
private boolean forceSystemScope;
private String mavenExecutable;
private boolean generateIvy;
}
Loading

0 comments on commit b61b87a

Please sign in to comment.