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

Commit

Permalink
Added two features: local artifacts as system-scope and build from ro…
Browse files Browse the repository at this point in the history
…ot project. some other improvements.
  • Loading branch information
lefou committed Feb 6, 2011
1 parent b61b87a commit f859a16
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 44 deletions.
18 changes: 13 additions & 5 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
cmvn-0.1.2:
* Fixed: Errors while parsing pom.xml.cmvn are silently dropped and
all content of template file is ignored further
* Fixed: Errors while parsing pom.xml.cmvn are silently dropped and all
content of template file is ignored further
* Let user specifiy Maven executable (--maven-bin)
* cmvn-0.1.1 looses configured state in some situations
* Also respect classifier when (distinct) comparing dependencies so
that it is possible to include same GA with different classifier in
dependency list (e.g. a normal jar and the tests-jar)
* Also respect classifier when (distinct) comparing dependencies so that it is
possible to include same GA with different classifier in dependency list
(e.g. a normal jar and the tests-jar)
* Improved ivy.xml and ivysettings.xml generation
* Experimental support for forced system-scope dependencies
* Experimental support for systen-scoped dependency to local available
artifacts, thus making the 'install' goal of maven unneccessary (using the
'package' goal is now equal and better)
* New default: --auto-regenerate
* Regenerating a sub-module does not change state outside of this
module/directory
* Added new build option --build-from-root to start Maven always from root
project with the complete reactor (alowing to use -am and -amd options)

cmvn-0.1.1:
* Generated files now have correct default XML namespace set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ public void run(final String[] args) {
// Configure mode
boolean runConfigure = false;
boolean forceGenerate = false;
boolean autoReconfigure = false;
boolean autoReconfigure = true;
final String[] mavenSettingsFile = new String[1];
final String[] mavenRepoDir = new String[1];
final String[] mavenBin = new String[1];

// Experimental
boolean generateIvyFiles = false;
boolean forceSystemScope = false;
boolean localArtifactsAsSystemScope = false;
boolean buildFromRootProject = false;

NextArgAction nextArgAction = null;

Expand Down Expand Up @@ -162,6 +164,10 @@ public void run(final String[] args) {
runMaven = true;
} else if (arg.equals("--force-system-scope")) {
forceSystemScope = true;
} else if (arg.equals("--local-artifacts-as-system-scope")) {
localArtifactsAsSystemScope = true;
} else if (arg.equals("--build-from-root")) {
buildFromRootProject = true;
} else if (arg.equals("--maven-bin")) {
nextArgAction = new NextArgAction() {
@Override
Expand Down Expand Up @@ -205,7 +211,23 @@ public NextArgAction processArg(final String arg) {
throw new RuntimeException("Invalid arguments in --configure mode: " + mavenArgs);
}

final CmvnProject project = new CmvnProject(new File(System.getProperty("user.dir")));
final File currentProjectDir = new File(System.getProperty("user.dir"));
CmvnProject projectCandidate = new CmvnProject(currentProjectDir);
File mvnExecDir = null;
String subDir = null;
if (buildFromRootProject) {
final String rootProjectFilePath = projectCandidate.getConfiguredState().getRootProjectFile();
final File rootProjectFile = new File(rootProjectFilePath);
if (currentProjectDir.getAbsolutePath().startsWith(rootProjectFile.getParentFile().getAbsolutePath())) {
final int index = rootProjectFile.getParentFile().getAbsolutePath().length();
subDir = currentProjectDir.getAbsolutePath().substring(index);
}
if (subDir != null && subDir.length() > 0) {
mvnExecDir = rootProjectFile.getParentFile();
projectCandidate = new CmvnProject(rootProjectFile);
}
}
final CmvnProject project = projectCandidate;

final boolean upToDate = project.isUpToDateRecursive();
System.out.println("Project up-to-date: " + upToDate);
Expand Down Expand Up @@ -243,6 +265,7 @@ public NextArgAction processArg(final String arg) {
}

if (regenerate) {

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

Expand Down Expand Up @@ -290,6 +313,8 @@ public NextArgAction processArg(final String arg) {
configureRequest.setMavenExecutable(file.getPath());
}
configureRequest.setForceSystemScope(forceSystemScope);
configureRequest.setSystemScopeForLocalProjects(localArtifactsAsSystemScope);

project.configureProjectRecursive(configureRequest);
}

Expand All @@ -313,6 +338,11 @@ public NextArgAction processArg(final String arg) {
// }

final ProcessBuilder pB = new ProcessBuilder(mvnArgs);
if (buildFromRootProject && mvnExecDir != null && subDir != null) {
pB.directory(mvnExecDir);
mvnArgs.add(3, "-pl");
mvnArgs.add(4, subDir);
}
Process process = null;
Thread outThread = null;
try {
Expand Down Expand Up @@ -377,22 +407,25 @@ private void printUsage() {
help += "Mode:\n";
help += " --build Enables BUILD mode\n";
help += " --configure Enables CONFIGURE mode\n";
help += " --regenerate Enables REGENERATE mode. Regenerate all files with same config\n";
help += " --clean Enables CLEAN mode\n";
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 += " --generate-ivy (Experimental) Generate ivy.xml and ivysettings.xml\n";
help += " --maven-repo DIR Use the given (existing) directory DIR as local Maven repository\n";
help += " --maven-settings FILE Use the following Maven settings file (may result in unrepeatable builds)\n";
help += " --maven-bin FILE Use the given Maven executable (instead of 'mvn')\n";
help += " --generate-ivy Generate ivy.xml and ivysettings.xml\n";
help += " --force-system-scope Forces all dependencies to be of system scope (in pom.xml)\n";
help += " --force-system-scope (Experimental) Forces all dependencies to be of system scope (in pom.xml)\n";
help += " --local-artifacts-as-system-scope (Experimental) Convert dependencies to local artifact to system-scope dependenies\n";
help += "\n";
help += "Options for BUILD mode:\n";
help += " --regenerate Automatically reconfigure if some source files are out-of-date\n";
help += " --reconfigure (Deprecated) Same as --regenerate\n";
help += " --build-from-root Run Maven from root project with additional '-pl <current-project>'\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 @@ -7,11 +7,11 @@
import de.tototec.tools.cmvn.configfile.KeyValue;
import de.tototec.tools.cmvn.configfile.KeyValueWithOptions;
import de.tototec.tools.cmvn.model.Build;
import de.tototec.tools.cmvn.model.CmvnProjectConfig;
import de.tototec.tools.cmvn.model.ConfigClassGenerator;
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.CmvnProjectConfig;
import de.tototec.tools.cmvn.model.Repository;

public enum CmvnConfigKey implements ProjectConfigKeyValueReader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class CmvnConfiguredState {
private boolean forceSystemScope;
private String mavenExecutable;
private boolean generateIvy;
private boolean referenceLocalArtifactsAsSystemScope;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public CmvnConfiguredState read() throws FileNotFoundException {
config.setMavenExecutable(value);
} else if (key.equals("generateIvy")) {
config.setGenerateIvy(value.equals("true"));
} else if (key.equals("referenceLocalArtifactsAsSystemScope")) {
config.setReferenceLocalArtifactsAsSystemScope(value.equals("true"));
} else {
System.out.println("Unknown config option found: " + keyValue);
}
Expand Down Expand Up @@ -80,6 +82,8 @@ public void write(final CmvnConfiguredState cmvnConfiguredState) throws FileNotF
}
configWriter.append("generateIvy: ").append(cmvnConfiguredState.isGenerateIvy() ? "true" : "false")
.append("\n");
configWriter.append("referenceLocalArtifactsAsSystemScope: ")
.append(cmvnConfiguredState.isReferenceLocalArtifactsAsSystemScope() ? "true" : "false").append("\n");

configWriter.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.tototec.tools.cmvn.configfile.KeyValue;
import de.tototec.tools.cmvn.configfile.bndlike.ConfigFileReaderImpl;
import de.tototec.tools.cmvn.model.ConfigClassGenerator;
import de.tototec.tools.cmvn.model.Dependency;
import de.tototec.tools.cmvn.model.Module;
import de.tototec.tools.cmvn.model.CmvnProjectConfig;

Expand Down Expand Up @@ -304,32 +305,52 @@ protected void configureProject(final ConfigureRequest configureRequest) {
if (configureRequest.getGenerateIvy() != null) {
configuredState.setGenerateIvy(configureRequest.getGenerateIvy().booleanValue());
}
if (configureRequest.getSystemScopeForLocalProjects() != null) {
configuredState.setReferenceLocalArtifactsAsSystemScope(configureRequest
.getSystemScopeForLocalProjects().booleanValue());
}
}

if (configuredState == null) {
throw new RuntimeException("Internal Error: No configured state");
}

persistCmvnState(configuredState);

// now generate files
generateProject(false);
}

private void persistCmvnState(final CmvnConfiguredState configuredState) {
// Persisting configured state
try {
new CmvnConfiguredStateFile(mavenConfigFile).write(configuredState);
this.configuredState = configuredState;
} catch (final FileNotFoundException e) {
throw new RuntimeException("Could not write maven config file: " + mavenConfigFile, e);
}

this.configuredState = configuredState;

generateProject(false);
}

protected void generateProject(final boolean onlyIfChanged) {
// we need an already persisted config

final CmvnConfiguredState cmvnConfig = getConfiguredState();
CmvnConfiguredState cmvnConfig = getConfiguredState();
if (cmvnConfig == null) {
throw new RuntimeException(
"The project is not configured. Please configure it first (cmvn --configure). Project: "
+ projectFile);
if (rootProject != null && rootProject.getConfiguredState() != null) {
// special case, the root project is not up-to-date because a
// new
// submodule was added. In this case we want it to beconfigured
// exactly as the root project
System.out.println("Configuring new project: " + projectFile);

cmvnConfig = rootProject.getConfiguredState();
persistCmvnState(cmvnConfig);
} else {

throw new RuntimeException(
"The project is not configured. Please configure it first (cmvn --configure). Project: "
+ projectFile);
}
}

if (onlyIfChanged && isUpToDate()) {
Expand All @@ -344,6 +365,21 @@ protected void generateProject(final boolean onlyIfChanged) {

// Generate Maven POM
final MavenPomGenerator mavenPomGenerator = new MavenPomGenerator(pomFile, cmvnConfig, projectConfig);
if (cmvnConfig.isReferenceLocalArtifactsAsSystemScope()) {
System.out.println("Converting local artifacts to system scope...");
final List<Dependency> localArtifacts = new LinkedList<Dependency>();
final List<CmvnProject> localProjects = rootProject != null ? rootProject.getMultiProjects()
: getMultiProjects();
for (final CmvnProject project : localProjects) {
final CmvnProjectConfig locProj = project.getProjectConfig();
final Dependency locArtifact = new Dependency(locProj.getProject().getGroupId(), locProj.getProject()
.getArtifactId(), locProj.getProject().getVersion());
locArtifact.setJarPath(new File(new File(locProj.getBaseDir(), "target"), locArtifact.getArtifactId()
+ "-" + locArtifact.getVersion() + ".jar").getAbsolutePath());
localArtifacts.add(locArtifact);
}
mavenPomGenerator.setLocalArtifacts(localArtifacts);
}
mavenPomGenerator.generate();

// Generate Ivy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tototec.tools.cmvn;

// Class generated by cmvn-0.1.2-SNAPSHOT
// Class generated by cmvn-0.1.1
public abstract class Config {

public static String cmvnVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class ConfigureRequest {
private String mavenRepo;
private Boolean generateIvy;
private Boolean forceSystemScope;
private Boolean systemScopeForLocalProjects;
private String mavenExecutable;
}
Loading

0 comments on commit f859a16

Please sign in to comment.