Skip to content

Commit

Permalink
Fixing Build
Browse files Browse the repository at this point in the history
Autocommit Sat Sep 02 08:15:17 AEST 2017
  • Loading branch information
mxro committed Sep 1, 2017
1 parent 2d80d68 commit 13e455e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>maven-tools</name>
<name>delight-maven-tools</name>
<comment></comment>
<projects>
</projects>
Expand Down
83 changes: 71 additions & 12 deletions src/main/java/de/mxro/maven/tools/MavenProject.java
Expand Up @@ -156,17 +156,21 @@ public static Dependency getMavenDependency(final File projectDir) {
}
throw new RuntimeException("No pom.xml found in project dir " + projectDir);
}

public static void setVersion(final File projectDir, final String version) {


public static File getPomFile(final File projectDir) {
for (final File file : projectDir.listFiles()) {
if (file.getName().equals("pom.xml")) {
replaceVersion(file, version);
return;

return file;
}
}
throw new RuntimeException("No pom.xml found in project dir " + projectDir);
}

public static void setVersion(final File projectDir, final String version) {
replaceVersion(getPomFile(projectDir), version);

}

/**
* Collects all the Maven projects under the defined root directory.
Expand Down Expand Up @@ -240,16 +244,11 @@ public static boolean replaceDependency(final File projectDir, final Dependency
return false;
}

// if (dependencies.size() != 1) {
// throw new RuntimeException("Illegal pom [" + pom + "]");
// }

// System.out.println(dependencies);



final Match children = dependencies.children("dependency");

// System.out.println(children);

boolean changed = false;
for (final org.w3c.dom.Element e : children) {

Expand Down Expand Up @@ -381,6 +380,66 @@ private static void replaceVersion(final File pomFile, final String newVersion)
}

}

public static void setArtifactId(final File pomFile, final String newArtifactId) {
try {
final List<String> lines = new ArrayList<String>();

final BufferedReader in = new BufferedReader(new FileReader(pomFile));
String line = in.readLine();
boolean found = false;
while (line != null) {

if (!found && line.contains("<artifactId>")) {
lines.add(" <artifactId>" + newArtifactId + "</artifactId>");
found = true;
} else {
lines.add(line);
}
line = in.readLine();
}
in.close();

final PrintWriter out = new PrintWriter(pomFile);
for (final String l : lines) {
out.println(l);
}
out.close();
} catch (final IOException ex) {
throw new RuntimeException(ex);
}

}

public static void setGroupId(final File pomFile, final String newGroupId) {
try {
final List<String> lines = new ArrayList<String>();

final BufferedReader in = new BufferedReader(new FileReader(pomFile));
String line = in.readLine();
boolean found = false;
while (line != null) {

if (!found && line.contains("<groupId>")) {
lines.add(" <groupId>" + newGroupId + "</groupId>");
found = true;
} else {
lines.add(line);
}
line = in.readLine();
}
in.close();

final PrintWriter out = new PrintWriter(pomFile);
for (final String l : lines) {
out.println(l);
}
out.close();
} catch (final IOException ex) {
throw new RuntimeException(ex);
}

}

public static String getName(final File pomFile) {
try {
Expand Down

0 comments on commit 13e455e

Please sign in to comment.