summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMickael Istria2012-05-31 04:34:10 (EDT)
committer Igor Fedorenko2012-06-24 16:57:59 (EDT)
commitac1faf8309705fb3ba444dfe8d10e00fcc00b02f (patch)
tree510d30ced86e7ae56bb7b55667eeec19ccbdfabc
parentc01e06f2f9c4ebf48d5f7d8ca58035e4b59b5d02 (diff)
downloadorg.eclipse.tycho.extras-ac1faf8309705fb3ba444dfe8d10e00fcc00b02f.zip
org.eclipse.tycho.extras-ac1faf8309705fb3ba444dfe8d10e00fcc00b02f.tar.gz
org.eclipse.tycho.extras-ac1faf8309705fb3ba444dfe8d10e00fcc00b02f.tar.bz2
378987 A plugin to validate .target files can be resolved
Change-Id: I11bb982372b6eaa63815c6fed98e2de91b97033a Conflicts: pom.xml
-rw-r--r--pom.xml1
-rw-r--r--target-platform-validation-plugin/pom.xml65
-rw-r--r--target-platform-validation-plugin/src/it/validateKO/invoke.properties2
-rw-r--r--target-platform-validation-plugin/src/it/validateKO/ko.target12
-rw-r--r--target-platform-validation-plugin/src/it/validateKO/pom.xml55
-rw-r--r--target-platform-validation-plugin/src/it/validateOK/invoke.properties2
-rw-r--r--target-platform-validation-plugin/src/it/validateOK/ok.target11
-rw-r--r--target-platform-validation-plugin/src/it/validateOK/pom.xml55
-rw-r--r--target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/invoke.properties2
-rw-r--r--target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ko.target12
-rw-r--r--target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ok.target11
-rw-r--r--target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/pom.xml58
-rw-r--r--target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPError.java39
-rw-r--r--target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPValidationMojo.java150
14 files changed, 475 insertions, 0 deletions
diff --git a/pom.xml b/pom.xml
index 93609e4..103ab89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,6 +84,7 @@
<module>tycho-source-feature-plugin</module>
<module>pack200</module>
<module>tycho-buildtimestamp-jgit</module>
+ <module>target-platform-validation-plugin</module>
</modules>
<repositories>
diff --git a/target-platform-validation-plugin/pom.xml b/target-platform-validation-plugin/pom.xml
new file mode 100644
index 0000000..d83f924
--- /dev/null
+++ b/target-platform-validation-plugin/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ - Copyright (c) 2012 Red Hat Inc. and others.
+ - All rights reserved. This program and the accompanying materials
+ - are made available under the terms of the Eclipse Public License v1.0
+ - which accompanies this distribution, and is available at
+ - http://www.eclipse.org/legal/epl-v10.html
+ -
+ - Contributors:
+ - Mickael Istria (Red Hat) - Initial API and implementation
+ -->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.tycho.extras</groupId>
+ <artifactId>tycho-extras</artifactId>
+ <version>0.16.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>target-platform-validation-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-p2-facade</artifactId>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>its</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.5</version>
+ <configuration>
+ <debug>true</debug>
+ <projectsDirectory>src/it</projectsDirectory>
+ <cloneProjectsTo>target/it</cloneProjectsTo>
+ <localRepositoryPath>target/local-repo</localRepositoryPath>
+ <invokerPropertiesFile>invoke.properties</invokerPropertiesFile>
+ <properties>
+ <tycho-version>${tycho-version}</tycho-version>
+ <tycho-extras-version>${project.version}</tycho-extras-version>
+ </properties>
+ </configuration>
+ <executions>
+ <execution>
+ <id>testOK</id>
+ <goals>
+ <goal>install</goal>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/target-platform-validation-plugin/src/it/validateKO/invoke.properties b/target-platform-validation-plugin/src/it/validateKO/invoke.properties
new file mode 100644
index 0000000..9a9fbfc
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateKO/invoke.properties
@@ -0,0 +1,2 @@
+invoker.goals = verify
+invoker.buildResult = failure \ No newline at end of file
diff --git a/target-platform-validation-plugin/src/it/validateKO/ko.target b/target-platform-validation-plugin/src/it/validateKO/ko.target
new file mode 100644
index 0000000..84dbdcf
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateKO/ko.target
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?pde version="3.8"?>
+
+<target name="ok" sequenceNumber="0">
+<locations>
+<location includeAllPlatforms="false" includeMode="planner" includeSource="true" type="InstallableUnit">
+<unit id="I_am_an_IU_that_does_not_exist" version="0.0.0"/>
+<unit id="org.eclipse.emf.sdk.feature.group" version="10.9.8"/>
+<repository location="http://download.eclipse.org/releases/indigo"/>
+</location>
+</locations>
+</target>
diff --git a/target-platform-validation-plugin/src/it/validateKO/pom.xml b/target-platform-validation-plugin/src/it/validateKO/pom.xml
new file mode 100644
index 0000000..ca98632
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateKO/pom.xml
@@ -0,0 +1,55 @@
+<?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>org.eclipse.tycho.extras.its</groupId>
+ <artifactId>validationOK</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>Test for validation plugin: 1 target, validation OK</name>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho.extras</groupId>
+ <artifactId>target-platform-validation-plugin</artifactId>
+ <version>${tycho-extras-version}</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>validate-target-platform</goal>
+ </goals>
+ <configuration>
+ <targetFiles>
+ <param>ko.target</param>
+ </targetFiles>
+ <failOnError>true</failOnError>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <!-- temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628 -->
+ <id>tycho-snapshots</id>
+ <url>https://oss.sonatype.org/content/groups/public/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
diff --git a/target-platform-validation-plugin/src/it/validateOK/invoke.properties b/target-platform-validation-plugin/src/it/validateOK/invoke.properties
new file mode 100644
index 0000000..ba7c662
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateOK/invoke.properties
@@ -0,0 +1,2 @@
+invoker.goals = verify
+invoker.buildResult = success \ No newline at end of file
diff --git a/target-platform-validation-plugin/src/it/validateOK/ok.target b/target-platform-validation-plugin/src/it/validateOK/ok.target
new file mode 100644
index 0000000..afc08bc
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateOK/ok.target
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?pde version="3.8"?>
+
+<target name="ok" sequenceNumber="0">
+<locations>
+<location includeAllPlatforms="false" includeMode="planner" includeSource="true" type="InstallableUnit">
+<unit id="org.eclipse.emf.sdk.feature.group" version="0.0.0"/>
+<repository location="http://download.eclipse.org/releases/indigo"/>
+</location>
+</locations>
+</target>
diff --git a/target-platform-validation-plugin/src/it/validateOK/pom.xml b/target-platform-validation-plugin/src/it/validateOK/pom.xml
new file mode 100644
index 0000000..05068a9
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validateOK/pom.xml
@@ -0,0 +1,55 @@
+<?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>org.eclipse.tycho.extras.its</groupId>
+ <artifactId>validationOK</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>Test for validation plugin: 1 target, validation OK</name>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho.extras</groupId>
+ <artifactId>target-platform-validation-plugin</artifactId>
+ <version>${tycho-extras-version}</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>validate-target-platform</goal>
+ </goals>
+ <configuration>
+ <targetFiles>
+ <param>ok.target</param>
+ </targetFiles>
+ <failOnError>true</failOnError>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <!-- temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628 -->
+ <id>tycho-snapshots</id>
+ <url>https://oss.sonatype.org/content/groups/public/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
diff --git a/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/invoke.properties b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/invoke.properties
new file mode 100644
index 0000000..9a9fbfc
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/invoke.properties
@@ -0,0 +1,2 @@
+invoker.goals = verify
+invoker.buildResult = failure \ No newline at end of file
diff --git a/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ko.target b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ko.target
new file mode 100644
index 0000000..84dbdcf
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ko.target
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?pde version="3.8"?>
+
+<target name="ok" sequenceNumber="0">
+<locations>
+<location includeAllPlatforms="false" includeMode="planner" includeSource="true" type="InstallableUnit">
+<unit id="I_am_an_IU_that_does_not_exist" version="0.0.0"/>
+<unit id="org.eclipse.emf.sdk.feature.group" version="10.9.8"/>
+<repository location="http://download.eclipse.org/releases/indigo"/>
+</location>
+</locations>
+</target>
diff --git a/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ok.target b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ok.target
new file mode 100644
index 0000000..afc08bc
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/ok.target
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?pde version="3.8"?>
+
+<target name="ok" sequenceNumber="0">
+<locations>
+<location includeAllPlatforms="false" includeMode="planner" includeSource="true" type="InstallableUnit">
+<unit id="org.eclipse.emf.sdk.feature.group" version="0.0.0"/>
+<repository location="http://download.eclipse.org/releases/indigo"/>
+</location>
+</locations>
+</target>
diff --git a/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/pom.xml b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/pom.xml
new file mode 100644
index 0000000..f1e82f8
--- /dev/null
+++ b/target-platform-validation-plugin/src/it/validate_OK_KO_OK_KO/pom.xml
@@ -0,0 +1,58 @@
+<?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>org.eclipse.tycho.extras.its</groupId>
+ <artifactId>validationOK</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>Test for validation plugin: 1 target, validation OK</name>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho.extras</groupId>
+ <artifactId>target-platform-validation-plugin</artifactId>
+ <version>${tycho-extras-version}</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>validate-target-platform</goal>
+ </goals>
+ <configuration>
+ <targetFiles>
+ <param>ok.target</param>
+ <param>ko.target</param>
+ <param>ok.target</param>
+ <param>ko.target</param>
+ </targetFiles>
+ <failOnError>true</failOnError>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <!-- temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=360628 -->
+ <id>tycho-snapshots</id>
+ <url>https://oss.sonatype.org/content/groups/public/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
diff --git a/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPError.java b/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPError.java
new file mode 100644
index 0000000..653cec9
--- /dev/null
+++ b/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPError.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael Istria (Red Hat). - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.extras.tpvalidator;
+
+import java.io.File;
+
+import org.eclipse.tycho.p2.target.facade.TargetDefinitionResolutionException;
+
+public class TPError extends Exception {
+
+ private File file;
+
+ public TPError(File file, Exception cause) {
+ super(cause);
+ this.file = file;
+ }
+
+ @Override
+ public String getMessage() {
+ StringBuilder res = new StringBuilder();
+ res.append("Could not resolve content of ");
+ res.append(this.file.getName());
+ res.append('\n');
+ if (getCause() instanceof TargetDefinitionResolutionException) {
+ TargetDefinitionResolutionException cause = (TargetDefinitionResolutionException)getCause();
+ res.append(cause.getMessage());
+ }
+ return res.toString();
+ }
+
+}
diff --git a/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPValidationMojo.java b/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPValidationMojo.java
new file mode 100644
index 0000000..bdafe83
--- /dev/null
+++ b/target-platform-validation-plugin/src/main/java/org/eclipse/tycho/extras/tpvalidator/TPValidationMojo.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael Istria (Red Hat). - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.extras.tpvalidator;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.logging.Logger;
+import org.eclipse.sisu.equinox.EquinoxServiceFactory;
+import org.eclipse.tycho.core.utils.ExecutionEnvironmentUtils;
+import org.eclipse.tycho.core.utils.PlatformPropertiesUtils;
+import org.eclipse.tycho.osgi.adapters.MavenLoggerAdapter;
+import org.eclipse.tycho.p2.resolver.TargetDefinitionFile;
+import org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult;
+import org.eclipse.tycho.p2.resolver.facade.P2Resolver;
+import org.eclipse.tycho.p2.resolver.facade.P2ResolverFactory;
+import org.eclipse.tycho.p2.target.facade.TargetPlatformBuilder;
+
+/**
+ * Validates that specified target platforms (.target files) contents
+ * can be resolved.
+ *
+ * @goal validate-target-platform
+ * @phase validate
+ */
+public class TPValidationMojo extends AbstractMojo
+{
+ /**
+ * .target files to validate
+ * @parameter
+ * @required
+ */
+ private File[] targetFiles;
+
+ /**
+ * whether to fail build or just print a warning
+ * when a validation fails
+ * @parameter default-value="true"
+ */
+ private boolean failOnError;
+
+
+ /** @component */
+ protected EquinoxServiceFactory equinox;
+
+ /**
+ * @parameter default-value="${project}"
+ */
+ private MavenProject project;
+
+ /** @component */
+ private Logger logger;
+
+ private P2ResolverFactory factory;
+ protected P2Resolver p2;
+ protected List<Map<String, String>> environment;
+
+ public void execute() throws MojoExecutionException {
+ this.factory = this.equinox.getService(P2ResolverFactory.class);
+ this.p2 = this.factory.createResolver(new MavenLoggerAdapter(this.logger, false));
+ initializeEnvironments();
+ p2.setEnvironments(environment);
+
+ List<TPError> errors = new ArrayList<TPError>();
+ for (File targetFile : this.targetFiles) {
+ try {
+ validateTarget(targetFile);
+ this.logger.info("OK!");
+ } catch (TPError ex) {
+ this.logger.info("Failed, see Error log below");
+ errors.add(ex);
+ }
+ }
+
+ if (!errors.isEmpty()) {
+ String message = createErrorMessage(errors);
+ this.logger.error(message);
+ if (this.failOnError) {
+ throw new MojoExecutionException(message);
+ }
+ }
+ }
+
+ private String createErrorMessage(List<TPError> errors) {
+ StringBuilder res = new StringBuilder();
+ res.append("Validation found errors in ");
+ res.append(errors.size());
+ res.append(" .target files:");
+ res.append("\n");
+ for (TPError error : errors) {
+ res.append(error.getMessage());
+ res.append("\n");
+ }
+ return res.toString();
+ }
+
+ private void validateTarget(File targetFile) throws TPError {
+ try {
+ // create resolver
+ this.logger.info("Validating " + targetFile + "...");
+ TargetPlatformBuilder resolutionContext;
+ resolutionContext = this.factory.createTargetPlatformBuilder(null, false);
+
+ TargetDefinitionFile target = TargetDefinitionFile.read(targetFile);
+ resolutionContext.addTargetDefinition(target, this.environment);
+ P2ResolutionResult result = this.p2.resolveMetadata(resolutionContext, this.environment.get(0));
+ } catch (Exception ex) {
+ throw new TPError(targetFile, ex);
+ }
+ }
+
+ /*
+ * Copied from version-bump-plugin
+ */
+ protected void initializeEnvironments() {
+ Properties properties = new Properties();
+ properties.put(PlatformPropertiesUtils.OSGI_OS, PlatformPropertiesUtils.getOS(properties));
+ properties.put(PlatformPropertiesUtils.OSGI_WS, PlatformPropertiesUtils.getWS(properties));
+ properties.put(PlatformPropertiesUtils.OSGI_ARCH, PlatformPropertiesUtils.getArch(properties));
+
+ // TODO this does not honour project <executionEnvironment> configuration
+ ExecutionEnvironmentUtils.loadVMProfile(properties);
+
+ // TODO does not belong here
+ properties.put("org.eclipse.update.install.features", "true");
+
+ Map<String, String> map = new LinkedHashMap<String, String>();
+ for (Object key : properties.keySet()) {
+ map.put(key.toString(), properties.getProperty(key.toString()));
+ }
+
+ this.environment = new ArrayList<Map<String, String>>();
+ this.environment.add(map);
+ }
+}