Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoMapping.java4
-rw-r--r--tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java56
-rw-r--r--tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java35
-rw-r--r--tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/.project3
-rw-r--r--tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/category.xml7
-rw-r--r--tycho-pomless/src/test/resources/modelreader/updatesites/missingProjectFile/category.xml7
-rw-r--r--tycho-pomless/src/test/resources/modelreader/updatesites/pom.xml11
-rw-r--r--tycho-pomless/src/test/resources/testpomless/updatesite/.project4
-rw-r--r--tycho-pomless/src/test/resources/testpomless/updatesite/category.xml7
9 files changed, 120 insertions, 14 deletions
diff --git a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoMapping.java b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoMapping.java
index 679ef26..b6ccddf 100644
--- a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoMapping.java
+++ b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoMapping.java
@@ -23,8 +23,8 @@ public class TychoMapping extends MappingSupport {
super("tycho");
// can't check for META-INF/MANIFEST.MF as this is in a subfolder and maven (and tycho) assumes
// in many places that the pom file is located in the project base dir, so we just use build.properties as a marker file
- setPomNames("build.properties");
- setAcceptLocationExtensions("build.properties", ".product");
+ setPomNames("build.properties", "category.xml");
+ setAcceptLocationExtensions("build.properties", ".product", "category.xml");
// make sure priority is lower than pom.xml (XmlMapping) so we can still override and use pom.xml if needed
setPriority(-2);
}
diff --git a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
index c5ce3ee..cb55984 100644
--- a/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
+++ b/tycho-pomless/src/main/java/org/eclipse/tycho/pomless/TychoModelReader.java
@@ -47,6 +47,7 @@ import org.sonatype.maven.polyglot.io.ModelReaderSupport;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
@@ -72,6 +73,7 @@ public class TychoModelReader extends ModelReaderSupport {
File projectRoot = new File(PolyglotModelUtil.getLocation(options)).getParentFile();
File manifestFile = new File(projectRoot, "META-INF/MANIFEST.MF");
File featureXml = new File(projectRoot, "feature.xml");
+ File categoryXml = new File(projectRoot, "category.xml");
File productXml = getProductFile(projectRoot);
if (manifestFile.isFile()) {
return createPomFromManifest(manifestFile);
@@ -79,9 +81,11 @@ public class TychoModelReader extends ModelReaderSupport {
return createPomFromFeatureXml(featureXml);
} else if (productXml != null) {
return createPomFromProductXml(productXml);
+ } else if (categoryXml.isFile()) {
+ return createPomFromCategoryXml(categoryXml);
} else {
- throw new IOException(
- "Neither META-INF/MANIFEST.MF nor feature.xml nor .product file found in " + projectRoot);
+ throw new IOException("Neither META-INF/MANIFEST.MF, feature.xml, .product nor category.xml file found in "
+ + projectRoot);
}
}
@@ -180,16 +184,7 @@ public class TychoModelReader extends ModelReaderSupport {
private Model createPomFromXmlFile(File xmlFile, String idAttributeName, String versionAttributeName,
String nameAttributeName, String vendorAttributeName) throws IOException, ModelParseException {
- Document doc;
- try {
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- doc = parser.parse(xmlFile);
- } catch (ParserConfigurationException e) {
- throw new RuntimeException(e);
- } catch (SAXException e) {
- throw new ModelParseException(e.getMessage(), -1, -1);
- }
- Element root = doc.getDocumentElement();
+ Element root = getRootXmlElement(xmlFile);
Model model = createModel();
model.setParent(findParent(xmlFile.getParentFile()));
String id = getXMLAttributeValue(root, idAttributeName);
@@ -235,6 +230,43 @@ public class TychoModelReader extends ModelReaderSupport {
return null;
}
+ private Model createPomFromCategoryXml(File categoryXml) throws ModelParseException, IOException {
+ Model model = createModel();
+ model.setPackaging("eclipse-repository");
+ Parent parent = findParent(categoryXml.getParentFile());
+ model.setParent(parent);
+ String projectName = getProjectName(categoryXml.getParentFile());
+ model.setArtifactId(projectName);
+ model.setVersion(parent.getVersion());
+ return model;
+ }
+
+ private String getProjectName(File projectRoot) throws IOException {
+ File projectFile = new File(projectRoot, ".project");
+ if (!projectFile.isFile()) {
+ throw new IOException("No .project file could be found in project directory: " + projectRoot);
+ }
+ Element projectDescription = getRootXmlElement(projectFile);
+ Node nameNode = projectDescription.getElementsByTagName("name").item(0);
+ if (nameNode == null) {
+ throw new IOException("No name element found in .project file " + projectFile);
+ }
+ return nameNode.getTextContent();
+ }
+
+ private Element getRootXmlElement(File xmlFile) throws IOException, ModelParseException {
+ Document doc;
+ try {
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ doc = parser.parse(xmlFile);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (SAXException e) {
+ throw new ModelParseException(e.getMessage(), -1, -1);
+ }
+ return doc.getDocumentElement();
+ }
+
private Model createModel() {
Model model = new Model();
model.setModelVersion("4.0.0");
diff --git a/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java b/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java
index 07bbadd..e186d3e 100644
--- a/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java
+++ b/tycho-pomless/src/test/java/org/eclipse/tycho/pomless/TychoModelReaderTest.java
@@ -202,6 +202,41 @@ public class TychoModelReaderTest extends PlexusTestCase {
}
}
+ @Test
+ public void testReadUpdateSite() throws ModelParseException, IOException {
+ File buildProperties = new File(getPolyglotTestDir(), "updatesite/build.properties");
+ Model model = tychoModelReader.read((Reader) null, createReaderOptions(buildProperties));
+ assertEquals("4.0.0", model.getModelVersion());
+ assertEquals("myUpdateSite", model.getArtifactId());
+ assertEquals("0.0.1-SNAPSHOT", model.getVersion());
+ assertEquals("eclipse-repository", model.getPackaging());
+ assertParent(model.getParent());
+ }
+
+ @Test
+ public void testReadUpdateSiteWithMissingProjectFile() {
+ File buildProperties = new File(getTestResourcesDir(),
+ "modelreader/updatesites/missingProjectFile/build.properties");
+ try {
+ tychoModelReader.read((Reader) null, createReaderOptions(buildProperties));
+ fail();
+ } catch (IOException e) {
+ assertTrue(e.getMessage().startsWith("No .project file could be found in project directory:"));
+ }
+ }
+
+ @Test
+ public void testReadUpdateSiteWithMissingNameElement() {
+ File buildProperties = new File(getTestResourcesDir(),
+ "modelreader/updatesites/missingNameElement/build.properties");
+ try {
+ tychoModelReader.read((Reader) null, createReaderOptions(buildProperties));
+ fail();
+ } catch (IOException e) {
+ assertTrue(e.getMessage().startsWith("No name element found in .project file"));
+ }
+ }
+
private void assertParent(Parent parent) {
assertNotNull(parent);
assertEquals("testParent.groupId", parent.getGroupId());
diff --git a/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/.project b/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/.project
new file mode 100644
index 0000000..74e5f5a
--- /dev/null
+++ b/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/.project
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+</projectDescription>
diff --git a/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/category.xml b/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/category.xml
new file mode 100644
index 0000000..3ab8de8
--- /dev/null
+++ b/tycho-pomless/src/test/resources/modelreader/updatesites/missingNameElement/category.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<site>
+ <feature id="pomless.feature" version="0.1.0.qualifier">
+ <category name="myCategory"/>
+ </feature>
+ <category-def name="myCategory" label="A Category"/>
+</site>
diff --git a/tycho-pomless/src/test/resources/modelreader/updatesites/missingProjectFile/category.xml b/tycho-pomless/src/test/resources/modelreader/updatesites/missingProjectFile/category.xml
new file mode 100644
index 0000000..3ab8de8
--- /dev/null
+++ b/tycho-pomless/src/test/resources/modelreader/updatesites/missingProjectFile/category.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<site>
+ <feature id="pomless.feature" version="0.1.0.qualifier">
+ <category name="myCategory"/>
+ </feature>
+ <category-def name="myCategory" label="A Category"/>
+</site>
diff --git a/tycho-pomless/src/test/resources/modelreader/updatesites/pom.xml b/tycho-pomless/src/test/resources/modelreader/updatesites/pom.xml
new file mode 100644
index 0000000..f221da0
--- /dev/null
+++ b/tycho-pomless/src/test/resources/modelreader/updatesites/pom.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>testParent.groupId</groupId>
+ <artifactId>updatesites-testparent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+</project>
diff --git a/tycho-pomless/src/test/resources/testpomless/updatesite/.project b/tycho-pomless/src/test/resources/testpomless/updatesite/.project
new file mode 100644
index 0000000..92f0b8d
--- /dev/null
+++ b/tycho-pomless/src/test/resources/testpomless/updatesite/.project
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>myUpdateSite</name>
+</projectDescription>
diff --git a/tycho-pomless/src/test/resources/testpomless/updatesite/category.xml b/tycho-pomless/src/test/resources/testpomless/updatesite/category.xml
new file mode 100644
index 0000000..3ab8de8
--- /dev/null
+++ b/tycho-pomless/src/test/resources/testpomless/updatesite/category.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<site>
+ <feature id="pomless.feature" version="0.1.0.qualifier">
+ <category name="myCategory"/>
+ </feature>
+ <category-def name="myCategory" label="A Category"/>
+</site>

Back to the top