[maven-repo-helper] 01/01: Turned POMOptions into a top level class
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Tue Feb 4 13:33:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to branch master
in repository maven-repo-helper.
commit 6d14e0a1609870375525272cb929d1c00c5fc307
Author: Emmanuel Bourg <ebourg at apache.org>
Date: Tue Feb 4 14:33:50 2014 +0100
Turned POMOptions into a top level class
---
.../java/org/debian/maven/repo/ListOfPOMs.java | 275 +++------------------
.../java/org/debian/maven/repo/POMOptions.java | 242 ++++++++++++++++++
.../java/org/debian/maven/repo/POMTransformer.java | 2 +-
.../java/org/debian/maven/repo/ListOfPOMsTest.java | 20 +-
.../java/org/debian/maven/repo/POMOptionsTest.java | 52 ++++
5 files changed, 327 insertions(+), 264 deletions(-)
diff --git a/src/main/java/org/debian/maven/repo/ListOfPOMs.java b/src/main/java/org/debian/maven/repo/ListOfPOMs.java
index b3a92e7..4d97056 100644
--- a/src/main/java/org/debian/maven/repo/ListOfPOMs.java
+++ b/src/main/java/org/debian/maven/repo/ListOfPOMs.java
@@ -66,9 +66,8 @@ public class ListOfPOMs {
* @return the path of the first pom, or null if not found
*/
public String getFirstPOM() {
- if (pomOptions == null) {
- readPomsFile();
- }
+ init();
+
if (!pomOptions.isEmpty()) {
return pomOptions.keySet().iterator().next();
}
@@ -79,9 +78,7 @@ public class ListOfPOMs {
* Process the pom files with the specified handler.
*/
public void foreachPoms(POMHandler handler) {
- if (pomOptions == null) {
- readPomsFile();
- }
+ init();
// process the ignored pom files
for (String pomPath: pomOptions.keySet()) {
@@ -114,8 +111,7 @@ public class ListOfPOMs {
* Returns the options associated to the specified pom file, or null if none exist.
*/
public POMOptions getPOMOptions(File pom) {
- String pomRelPath = relativePath(pom);
- return getPOMOptions(pomRelPath);
+ return getPOMOptions(relativePath(pom));
}
/**
@@ -137,8 +133,7 @@ public class ListOfPOMs {
* The file is added to the list if not already present.
*/
public POMOptions getOrCreatePOMOptions(File pom) {
- String pomRelPath = relativePath(pom);
- return getOrCreatePOMOptions(pomRelPath);
+ return getOrCreatePOMOptions(relativePath(pom));
}
/**
@@ -154,9 +149,8 @@ public class ListOfPOMs {
}
public Map<String, POMOptions> getPomOptions() {
- if (pomOptions == null) {
- readPomsFile();
- }
+ init();
+
return pomOptions;
}
@@ -167,8 +161,7 @@ public class ListOfPOMs {
* @return the default options associated to the pom
*/
public POMOptions addPOM(File pom) {
- String pomRelPath = relativePath(pom);
- return addPOM(pomRelPath);
+ return addPOM(relativePath(pom));
}
/**
@@ -178,9 +171,7 @@ public class ListOfPOMs {
* @return the default options associated to the pom
*/
public POMOptions addPOM(String pomPath) {
- if (pomOptions == null) {
- readPomsFile();
- }
+ init();
POMOptions options = new POMOptions();
pomOptions.put(pomPath, options);
@@ -197,70 +188,42 @@ public class ListOfPOMs {
/**
* Parses the file containing the list of pom files.
*/
- private void readPomsFile() {
- if (pomOptions == null) {
- pomOptions = new LinkedHashMap<String, POMOptions>();
+ private void init() {
+ if (pomOptions != null) {
+ // the list is already initialized
+ return;
}
+
+ pomOptions = new LinkedHashMap<String, POMOptions>();
if (poms == null || !poms.exists()) {
return;
}
-
+
+ if (verbose) {
+ System.out.println("Loading the list of poms from " + poms.getAbsolutePath() + "...");
+ }
+
try {
- if (verbose) {
- System.out.println("Read list of poms from " + poms.getAbsolutePath());
- }
BufferedReader reader = new BufferedReader(new FileReader(poms));
String line;
while ((line = reader.readLine()) != null) {
- line = line.trim();
- StringTokenizer st = new StringTokenizer(line, " \t");
- if (!st.hasMoreTokens() || line.startsWith("#")) {
+ line = line.trim().replaceAll("\\s", " ");
+ if (line.startsWith("#") || line.length() == 0) {
+ // skip comments and empty lines
continue;
}
- String pomPath = st.nextToken();
- POMOptions options = addPOM(pomPath);
+ String pomPath = line.contains(" ") ? line.substring(0, line.indexOf(" ")) : line;
+ POMOptions options = POMOptions.parse(line.substring(pomPath.length()));
- // parse the options
- while (st.hasMoreTokens()) {
- String option = st.nextToken().trim();
- if ("--ignore".equals(option)) {
- options.setIgnore(true);
- break;
- } else if ("--no-parent".equals(option)) {
- options.setNoParent(true);
- } else if (option.startsWith("--package=")) {
- options.setDestPackage(option.substring("--package=".length()));
- } else if ("--has-package-version".equals(option)) {
- options.setHasPackageVersion(true);
- } else if (option.startsWith("--keep-elements=")) {
- options.setKeepElements(option.substring("--keep-elements=".length()));
- } else if (option.startsWith("--artifact=")) {
- options.setArtifact(option.substring("--artifact=".length()));
- } else if ("--java-lib".equals(option)) {
- options.setJavaLib(true);
- } else if (option.startsWith("--usj-name=")) {
- options.setUsjName(option.substring("--usj-name=".length()));
- } else if (option.startsWith("--usj-version=")) {
- options.setUsjVersion(option.substring("--usj-version=".length()));
- } else if ("--no-usj-versionless".equals(option)) {
- options.setNoUsjVersionless(true);
- } else if (option.startsWith("--dest-jar=")) {
- options.setDestJar(option.substring("--dest-jar=".length()));
- } else if (option.startsWith("--classifier=")) {
- options.setClassifier(option.substring("--classifier=".length()));
- } else if (option.startsWith("--site-xml=")) {
- options.setSiteXml(option.substring("--site-xml=".length()));
- } else if ("--ignore-pom".equals(option)) {
- options.setIgnorePOM(true);
- }
- }
+ pomOptions.put(pomPath, options);
if (verbose) {
System.out.println(pomPath + options);
}
}
+
reader.close();
} catch (IOException e) {
log.log(Level.SEVERE, "Unable to read the list of poms from " + poms, e);
@@ -273,9 +236,8 @@ public class ListOfPOMs {
public void save() {
if (poms != null) {
try {
- if (pomOptions == null) {
- readPomsFile();
- }
+ init();
+
PrintWriter out = new PrintWriter(new FileWriter(poms));
out.println("# List of POM files for the package");
out.println("# Format of this file is:");
@@ -314,183 +276,4 @@ public class ListOfPOMs {
}
}
}
-
- /**
- * The options associated to a pom file.
- */
- public static class POMOptions {
- private boolean ignore;
- private boolean ignorePOM;
- private boolean noParent;
- private boolean hasPackageVersion;
- private String destPackage;
- private String keepElements;
- private String artifact;
- private boolean javaLib;
- private String usjName;
- private String usjVersion;
- private String destJar;
- private boolean noUsjVersionless;
- private String classifier;
- private String siteXml;
-
- public boolean isIgnore() {
- return ignore;
- }
-
- public void setIgnore(boolean ignore) {
- this.ignore = ignore;
- }
-
- public boolean isIgnorePOM() {
- return ignorePOM;
- }
-
- public void setIgnorePOM(boolean ignorePOM) {
- this.ignorePOM = ignorePOM;
- }
-
- public boolean isNoParent() {
- return noParent;
- }
-
- public void setNoParent(boolean noParent) {
- this.noParent = noParent;
- }
-
- public String getDestPackage() {
- return destPackage;
- }
-
- public void setDestPackage(String destPackage) {
- this.destPackage = destPackage;
- }
-
- public boolean getHasPackageVersion() {
- return hasPackageVersion;
- }
-
- public void setHasPackageVersion(boolean hasPackageVersion) {
- this.hasPackageVersion = hasPackageVersion;
- }
-
- public String getKeepElements() {
- return keepElements;
- }
-
- public void setKeepElements(String keepElements) {
- this.keepElements = keepElements;
- }
-
- public String getArtifact() {
- return artifact;
- }
-
- public void setArtifact(String artifact) {
- this.artifact = artifact;
- }
-
- public boolean isJavaLib() {
- return javaLib;
- }
-
- public void setJavaLib(boolean javaLib) {
- this.javaLib = javaLib;
- }
-
- public String getUsjName() {
- return usjName;
- }
-
- public void setUsjName(String usjName) {
- this.usjName = usjName;
- }
-
- public String getUsjVersion() {
- return usjVersion;
- }
-
- public void setUsjVersion(String usjVersion) {
- this.usjVersion = usjVersion;
- }
-
- public String getDestJar() {
- return destJar;
- }
-
- public void setDestJar(String destJar) {
- this.destJar = destJar;
- }
-
- public boolean isNoUsjVersionless() {
- return noUsjVersionless;
- }
-
- public void setNoUsjVersionless(boolean noUsjVersionless) {
- this.noUsjVersionless = noUsjVersionless;
- }
-
- public String getClassifier() {
- return classifier;
- }
-
- public void setClassifier(String classifier) {
- this.classifier = classifier;
- }
-
- public String getSiteXml() {
- return siteXml;
- }
-
- public void setSiteXml(String siteXml) {
- this.siteXml = siteXml;
- }
-
- public String toString() {
- if (ignore) {
- return " --ignore";
- }
- String options = "";
- if (noParent) {
- options += " --no-parent";
- }
- if (hasPackageVersion) {
- options += " --has-package-version";
- }
- if (destPackage != null) {
- options += " --package=" + destPackage;
- }
- if (keepElements != null) {
- options += " --keep-elements=" + keepElements;
- }
- if (artifact != null) {
- options += " --artifact=" + artifact;
- }
- if (javaLib) {
- options += " --java-lib";
- }
- if (usjName != null) {
- options += " --usj-name=" + usjName;
- }
- if (usjVersion != null) {
- options += " --usj-version=" + usjVersion;
- }
- if (destJar != null) {
- options += " --dest-jar=" + destJar;
- }
- if (noUsjVersionless) {
- options += " --no-usj-versionless";
- }
- if (classifier != null) {
- options += " --classifier=" + classifier;
- }
- if (siteXml != null) {
- options += " --site-xml=" + siteXml;
- }
- if (ignorePOM) {
- options += " --ignore-pom";
- }
- return options;
- }
- }
}
diff --git a/src/main/java/org/debian/maven/repo/POMOptions.java b/src/main/java/org/debian/maven/repo/POMOptions.java
new file mode 100644
index 0000000..d0e9657
--- /dev/null
+++ b/src/main/java/org/debian/maven/repo/POMOptions.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2009 Ludovic Claude.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.debian.maven.repo;
+
+import java.util.StringTokenizer;
+
+/**
+ * The options associated to a pom file.
+ */
+public class POMOptions {
+
+ private boolean ignore;
+ private boolean ignorePOM;
+ private boolean noParent;
+ private boolean hasPackageVersion;
+ private String destPackage;
+ private String keepElements;
+ private String artifact;
+ private boolean javaLib;
+ private String usjName;
+ private String usjVersion;
+ private String destJar;
+ private boolean noUsjVersionless;
+ private String classifier;
+ private String siteXml;
+
+ public boolean isIgnore() {
+ return ignore;
+ }
+
+ public void setIgnore(boolean ignore) {
+ this.ignore = ignore;
+ }
+
+ public boolean isIgnorePOM() {
+ return ignorePOM;
+ }
+
+ public void setIgnorePOM(boolean ignorePOM) {
+ this.ignorePOM = ignorePOM;
+ }
+
+ public boolean isNoParent() {
+ return noParent;
+ }
+
+ public void setNoParent(boolean noParent) {
+ this.noParent = noParent;
+ }
+
+ public String getDestPackage() {
+ return destPackage;
+ }
+
+ public void setDestPackage(String destPackage) {
+ this.destPackage = destPackage;
+ }
+
+ public boolean getHasPackageVersion() {
+ return hasPackageVersion;
+ }
+
+ public void setHasPackageVersion(boolean hasPackageVersion) {
+ this.hasPackageVersion = hasPackageVersion;
+ }
+
+ public String getKeepElements() {
+ return keepElements;
+ }
+
+ public void setKeepElements(String keepElements) {
+ this.keepElements = keepElements;
+ }
+
+ public String getArtifact() {
+ return artifact;
+ }
+
+ public void setArtifact(String artifact) {
+ this.artifact = artifact;
+ }
+
+ public boolean isJavaLib() {
+ return javaLib;
+ }
+
+ public void setJavaLib(boolean javaLib) {
+ this.javaLib = javaLib;
+ }
+
+ public String getUsjName() {
+ return usjName;
+ }
+
+ public void setUsjName(String usjName) {
+ this.usjName = usjName;
+ }
+
+ public String getUsjVersion() {
+ return usjVersion;
+ }
+
+ public void setUsjVersion(String usjVersion) {
+ this.usjVersion = usjVersion;
+ }
+
+ public String getDestJar() {
+ return destJar;
+ }
+
+ public void setDestJar(String destJar) {
+ this.destJar = destJar;
+ }
+
+ public boolean isNoUsjVersionless() {
+ return noUsjVersionless;
+ }
+
+ public void setNoUsjVersionless(boolean noUsjVersionless) {
+ this.noUsjVersionless = noUsjVersionless;
+ }
+
+ public String getClassifier() {
+ return classifier;
+ }
+
+ public void setClassifier(String classifier) {
+ this.classifier = classifier;
+ }
+
+ public String getSiteXml() {
+ return siteXml;
+ }
+
+ public void setSiteXml(String siteXml) {
+ this.siteXml = siteXml;
+ }
+
+ public static POMOptions parse(String line) {
+ StringTokenizer st = new StringTokenizer(line, " \t");
+
+ POMOptions options = new POMOptions();
+
+ // parse the options
+ while (st.hasMoreTokens()) {
+ String option = st.nextToken().trim();
+ if ("--ignore".equals(option)) {
+ options.setIgnore(true);
+ break;
+ } else if ("--no-parent".equals(option)) {
+ options.setNoParent(true);
+ } else if (option.startsWith("--package=")) {
+ options.setDestPackage(option.substring("--package=".length()));
+ } else if ("--has-package-version".equals(option)) {
+ options.setHasPackageVersion(true);
+ } else if (option.startsWith("--keep-elements=")) {
+ options.setKeepElements(option.substring("--keep-elements=".length()));
+ } else if (option.startsWith("--artifact=")) {
+ options.setArtifact(option.substring("--artifact=".length()));
+ } else if ("--java-lib".equals(option)) {
+ options.setJavaLib(true);
+ } else if (option.startsWith("--usj-name=")) {
+ options.setUsjName(option.substring("--usj-name=".length()));
+ } else if (option.startsWith("--usj-version=")) {
+ options.setUsjVersion(option.substring("--usj-version=".length()));
+ } else if ("--no-usj-versionless".equals(option)) {
+ options.setNoUsjVersionless(true);
+ } else if (option.startsWith("--dest-jar=")) {
+ options.setDestJar(option.substring("--dest-jar=".length()));
+ } else if (option.startsWith("--classifier=")) {
+ options.setClassifier(option.substring("--classifier=".length()));
+ } else if (option.startsWith("--site-xml=")) {
+ options.setSiteXml(option.substring("--site-xml=".length()));
+ } else if ("--ignore-pom".equals(option)) {
+ options.setIgnorePOM(true);
+ }
+ }
+
+ return options;
+ }
+
+ public String toString() {
+ if (ignore) {
+ return " --ignore";
+ }
+ String options = "";
+ if (noParent) {
+ options += " --no-parent";
+ }
+ if (hasPackageVersion) {
+ options += " --has-package-version";
+ }
+ if (destPackage != null) {
+ options += " --package=" + destPackage;
+ }
+ if (keepElements != null) {
+ options += " --keep-elements=" + keepElements;
+ }
+ if (artifact != null) {
+ options += " --artifact=" + artifact;
+ }
+ if (javaLib) {
+ options += " --java-lib";
+ }
+ if (usjName != null) {
+ options += " --usj-name=" + usjName;
+ }
+ if (usjVersion != null) {
+ options += " --usj-version=" + usjVersion;
+ }
+ if (destJar != null) {
+ options += " --dest-jar=" + destJar;
+ }
+ if (noUsjVersionless) {
+ options += " --no-usj-versionless";
+ }
+ if (classifier != null) {
+ options += " --classifier=" + classifier;
+ }
+ if (siteXml != null) {
+ options += " --site-xml=" + siteXml;
+ }
+ if (ignorePOM) {
+ options += " --ignore-pom";
+ }
+ return options;
+ }
+}
diff --git a/src/main/java/org/debian/maven/repo/POMTransformer.java b/src/main/java/org/debian/maven/repo/POMTransformer.java
index 0f119b7..192bd8c 100644
--- a/src/main/java/org/debian/maven/repo/POMTransformer.java
+++ b/src/main/java/org/debian/maven/repo/POMTransformer.java
@@ -751,7 +751,7 @@ public class POMTransformer extends POMReader {
if (singlePom) {
String pomPath = argsMap.getFirstArgument();
listOfPOMs = new ListOfPOMs();
- ListOfPOMs.POMOptions options = listOfPOMs.addPOM(pomPath);
+ POMOptions options = listOfPOMs.addPOM(pomPath);
options.setNoParent(noParent);
} else {
String pomsFileName = argsMap.getFirstArgument("debian/" + debianPackage + ".poms");
diff --git a/src/test/java/org/debian/maven/repo/ListOfPOMsTest.java b/src/test/java/org/debian/maven/repo/ListOfPOMsTest.java
index f9af22c..2095638 100644
--- a/src/test/java/org/debian/maven/repo/ListOfPOMsTest.java
+++ b/src/test/java/org/debian/maven/repo/ListOfPOMsTest.java
@@ -53,7 +53,7 @@ public class ListOfPOMsTest {
public void testAddPom() {
File pom = new File("pom.xml");
ListOfPOMs poms = new ListOfPOMs();
- ListOfPOMs.POMOptions options = poms.getPOMOptions(pom);
+ POMOptions options = poms.getPOMOptions(pom);
assertNull(options);
poms.addPOM(pom);
@@ -64,11 +64,11 @@ public class ListOfPOMsTest {
@Test
public void testGetOrCreatePOMOptions() {
ListOfPOMs poms = new ListOfPOMs();
- ListOfPOMs.POMOptions options = poms.getOrCreatePOMOptions(new File("pom.xml"));
+ POMOptions options = poms.getOrCreatePOMOptions(new File("pom.xml"));
assertNotNull(options);
assertNotNull(poms.getFirstPOM());
- ListOfPOMs.POMOptions options2 = poms.getOrCreatePOMOptions(new File("pom.xml"));
+ POMOptions options2 = poms.getOrCreatePOMOptions(new File("pom.xml"));
assertTrue(options == options2);
}
@@ -104,18 +104,4 @@ public class ListOfPOMsTest {
assertFalse(pomFiles.isEmpty());
assertFalse(ignoredPomFiles.isEmpty());
}
-
- @Test
- public void testOptionsToString() {
- ListOfPOMs.POMOptions options = new ListOfPOMs.POMOptions();
- options.setIgnore(true);
- options.setNoParent(true);
-
- assertEquals(" --ignore", options.toString());
-
- options.setIgnore(false);
- options.setHasPackageVersion(true);
-
- assertEquals(" --no-parent --has-package-version", options.toString());
- }
}
diff --git a/src/test/java/org/debian/maven/repo/POMOptionsTest.java b/src/test/java/org/debian/maven/repo/POMOptionsTest.java
new file mode 100644
index 0000000..0c0dc7b
--- /dev/null
+++ b/src/test/java/org/debian/maven/repo/POMOptionsTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009 Ludovic Claude.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.debian.maven.repo;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Emmanuel Bourg
+ * @version $Revision$, $Date$
+ */
+public class POMOptionsTest {
+
+ @Test
+ public void testParse() {
+ POMOptions options = POMOptions.parse("--has-package-version --java-lib --no-parent");
+ assertTrue(options.getHasPackageVersion());
+ assertTrue(options.isJavaLib());
+ assertTrue(options.isNoParent());
+ assertFalse(options.isIgnorePOM());
+ assertFalse(options.isNoUsjVersionless());
+ }
+
+ @Test
+ public void testOptionsToString() {
+ POMOptions options = new POMOptions();
+ options.setIgnore(true);
+ options.setNoParent(true);
+
+ assertEquals(" --ignore", options.toString());
+
+ options.setIgnore(false);
+ options.setHasPackageVersion(true);
+
+ assertEquals(" --no-parent --has-package-version", options.toString());
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-repo-helper.git
More information about the pkg-java-commits
mailing list