| author | Jan Sievers | 2012-01-12 10:38:59 (EST) |
|---|---|---|
| committer | Jan Sievers | 2012-01-30 11:33:17 (EST) |
| commit | 1a043f098ced2f6f1e1a532f836b0db68bc4f397 (patch) (side-by-side diff) | |
| tree | bba7431907ae5b3458f0b5a1c7be9ceccfd50e72 | |
| parent | 066a12dc3686f14c637f901fc413d6959830f682 (diff) | |
| download | org.eclipse.tycho-1a043f098ced2f6f1e1a532f836b0db68bc4f397.zip org.eclipse.tycho-1a043f098ced2f6f1e1a532f836b0db68bc4f397.tar.gz org.eclipse.tycho-1a043f098ced2f6f1e1a532f836b0db68bc4f397.tar.bz2 | |
35005 Validate bin.includes and src.includes
For plugins and features, bin.includes entries in
build.properties are validated
if they match any files in the project root when
packaging the plugin/feature jar.
src.includes entries in build.properties are validated
if they match any files when packaging the source bundle
jar.
Fail the build in case a bin/src.include pattern
does not mach any files.
Corrected existing integration tests which contained
invalid bin.includes entries.
14 files changed, 176 insertions, 21 deletions
diff --git a/tycho-its/projects/TYCHO0294ProductP2TargetPlatformResolver/bundle/build.properties b/tycho-its/projects/TYCHO0294ProductP2TargetPlatformResolver/bundle/build.properties index 2b0d95b..5f22cdd 100644 --- a/tycho-its/projects/TYCHO0294ProductP2TargetPlatformResolver/bundle/build.properties +++ b/tycho-its/projects/TYCHO0294ProductP2TargetPlatformResolver/bundle/build.properties @@ -1,5 +1 @@ -source.. = src/ -output.. = bin/ -bin.includes = plugin.xml,\ - META-INF/,\ - . +bin.includes = META-INF/ diff --git a/tycho-its/projects/TYCHO0356runSingleTest/build.properties b/tycho-its/projects/TYCHO0356runSingleTest/build.properties index fc8c47c..f250f99 100644 --- a/tycho-its/projects/TYCHO0356runSingleTest/build.properties +++ b/tycho-its/projects/TYCHO0356runSingleTest/build.properties @@ -1,5 +1,4 @@ output.. = bin/ bin.includes = META-INF/,\ - .,\ - OSGI-INF/component.xml + . source.. = src/ diff --git a/tycho-its/projects/TYCHO359corruptedArtifactDownloads/build.properties b/tycho-its/projects/TYCHO359corruptedArtifactDownloads/build.properties index 34d2e4d..5f22cdd 100644 --- a/tycho-its/projects/TYCHO359corruptedArtifactDownloads/build.properties +++ b/tycho-its/projects/TYCHO359corruptedArtifactDownloads/build.properties @@ -1,4 +1 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . +bin.includes = META-INF/ diff --git a/tycho-its/projects/pomGenerator.testSuite/bundle/build.properties b/tycho-its/projects/pomGenerator.testSuite/bundle/build.properties index e9863e2..34d2e4d 100644 --- a/tycho-its/projects/pomGenerator.testSuite/bundle/build.properties +++ b/tycho-its/projects/pomGenerator.testSuite/bundle/build.properties @@ -1,5 +1,4 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - .,\ - plugin.xml + . diff --git a/tycho-its/projects/target.offlineMode/bundle/build.properties b/tycho-its/projects/target.offlineMode/bundle/build.properties index 34d2e4d..5f22cdd 100644 --- a/tycho-its/projects/target.offlineMode/bundle/build.properties +++ b/tycho-its/projects/target.offlineMode/bundle/build.properties @@ -1,4 +1 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . +bin.includes = META-INF/ diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IncludeValidationHelper.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IncludeValidationHelper.java new file mode 100644 index 0000000..180440c --- a/dev/null +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IncludeValidationHelper.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2012 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.tycho.packaging; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.DirectoryScanner; +import org.eclipse.tycho.core.facade.BuildProperties; + +public class IncludeValidationHelper { + + private IncludeValidationHelper() { + } + + public static void checkBinIncludesExist(MavenProject project, BuildProperties buildProperties, + String... ignoredIncludes) throws MojoExecutionException { + checkIncludesExist("bin.includes", buildProperties.getBinIncludes(), project, ignoredIncludes); + } + + public static void checkSourceIncludesExist(MavenProject project, BuildProperties buildProperties) + throws MojoExecutionException { + checkIncludesExist("src.includes", buildProperties.getSourceIncludes(), project); + } + + private static void checkIncludesExist(String buildPropertiesKey, List<String> includePatterns, + MavenProject project, String... ignoredIncludes) throws MojoExecutionException { + File baseDir = project.getBasedir(); + List<String> nonMatchingIncludes = new ArrayList<String>(); + List<String> ignoreList = Arrays.asList(ignoredIncludes); + for (String includePattern : includePatterns) { + if (ignoreList.contains(includePattern)) { + continue; + } + if (new File(baseDir, includePattern).exists()) { + continue; + } + // it does not exist as a file nor dir. Try if it matches any files as ant pattern + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setIncludes(new String[] { includePattern }); + scanner.setBasedir(baseDir); + scanner.scan(); + if (scanner.getIncludedFiles().length == 0) { + nonMatchingIncludes.add(includePattern); + } + } + if (nonMatchingIncludes.size() > 0) { + throw new MojoExecutionException(new File(baseDir, "build.properties").getAbsolutePath() + ": " + + buildPropertiesKey + " value(s) " + nonMatchingIncludes + " do not match any files."); + } + } + +} diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackageFeatureMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackageFeatureMojo.java index fa673ff..1fcd7f9 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackageFeatureMojo.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackageFeatureMojo.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.tycho.packaging; +import static org.eclipse.tycho.packaging.IncludeValidationHelper.checkBinIncludesExist; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -124,6 +126,7 @@ public class PackageFeatureMojo extends AbstractTychoPackagingMojo { } BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir()); + checkBinIncludesExist(project, buildProperties); File featureProperties = getFeatureProperties(licenseFeature, buildProperties); diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java index b0185ff..4562e1a 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/PackagePluginMojo.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.tycho.packaging; +import static org.eclipse.tycho.packaging.IncludeValidationHelper.checkBinIncludesExist; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -115,11 +117,11 @@ public class PackagePluginMojo extends AbstractTychoPackagingMojo { pluginFile.delete(); } BuildProperties buildProperties = pdeProject.getBuildProperties(); - List<String> binInludesList = buildProperties.getBinIncludes(); + List<String> binIncludesList = buildProperties.getBinIncludes(); List<String> binExcludesList = buildProperties.getBinExcludes(); BuildOutputJar dotOutputJar = pdeProject.getDotOutputJar(); - if (dotOutputJar != null && binInludesList.contains(dotOutputJar.getName())) { + if (dotOutputJar != null && binIncludesList.contains(dotOutputJar.getName())) { String prefix; if (dotOutputJar.getName().endsWith("/")) { // prefix is a relative path to folder inside the jar: something like WEB-INF/classes/ @@ -131,8 +133,10 @@ public class PackagePluginMojo extends AbstractTychoPackagingMojo { archiver.getArchiver().addDirectory(dotOutputJar.getOutputDirectory(), prefix); } - if (binInludesList.size() > 0) { - archiver.getArchiver().addFileSet(getFileSet(project.getBasedir(), binInludesList, binExcludesList)); + if (binIncludesList.size() > 0) { + String dotOutputJarName = dotOutputJar != null ? dotOutputJar.getName() : "."; + checkBinIncludesExist(project, buildProperties, dotOutputJarName); + archiver.getArchiver().addFileSet(getFileSet(project.getBasedir(), binIncludesList, binExcludesList)); } File manifest = updateManifest(); diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java new file mode 100644 index 0000000..6eba922 --- a/dev/null +++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/packaging/IncludeValidationHelperTest.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2012 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ + +package org.eclipse.tycho.packaging; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.eclipse.tycho.core.facade.BuildPropertiesImpl; +import org.eclipse.tycho.testing.TestUtil; +import org.junit.Test; + +public class IncludeValidationHelperTest { + + @Test + public void testCheckSourceIncludesExistAntPatterns() throws Exception { + BuildPropertiesImpl buildProperties = createBuildProperties("src.includes", "foo.txt, bar*,**/*.me"); + IncludeValidationHelper.checkSourceIncludesExist(createMockProject(), buildProperties); + } + + @Test + public void testCheckBinIncludesExistAntPatterns() throws Exception { + BuildPropertiesImpl buildProperties = createBuildProperties("bin.includes", "foo.txt, bar*,**/*.me"); + IncludeValidationHelper.checkBinIncludesExist(createMockProject(), buildProperties); + } + + @Test + public void testCheckBinIncludesDontExist() throws Exception { + BuildPropertiesImpl buildProperties = createBuildProperties("bin.includes", "foo2.txt, bar2*,**/*.me"); + try { + IncludeValidationHelper.checkBinIncludesExist(createMockProject(), buildProperties); + fail(); + } catch (MojoExecutionException e) { + assertStringContains("bin.includes value(s) [foo2.txt, bar2*] do not match any files.", e.getMessage()); + } + } + + @Test + public void testCheckSourceIncludesDontExist() throws Exception { + BuildPropertiesImpl buildProperties = createBuildProperties("src.includes", "foo3, bar3*,**/*.me"); + try { + IncludeValidationHelper.checkSourceIncludesExist(createMockProject(), buildProperties); + fail(); + } catch (MojoExecutionException e) { + assertStringContains("src.includes value(s) [foo3, bar3*] do not match any files.", e.getMessage()); + } + } + + @Test + public void testCheckBinIncludesExistWithIgnoredPatterns() throws Exception { + BuildPropertiesImpl buildProperties = createBuildProperties("bin.includes", + "foo.txt, bar*,**/*.me,TO_BE_IGNORED"); + IncludeValidationHelper.checkBinIncludesExist(createMockProject(), buildProperties, "TO_BE_IGNORED"); + } + + private void assertStringContains(String expected, String actual) { + assertTrue("String '" + expected + "' not found in '" + actual + "'", actual.contains(expected)); + } + + private MavenProject createMockProject() throws IOException { + MavenProject mavenProject = new MavenProject(); + mavenProject.setFile(new File(TestUtil.getBasedir("projects/validationHelper/binInclude"), "pom.xml")); + return mavenProject; + } + + private BuildPropertiesImpl createBuildProperties(String key, String value) { + Properties properties = new Properties(); + properties.setProperty(key, value); + BuildPropertiesImpl buildProperties = new BuildPropertiesImpl(properties); + return buildProperties; + } +} diff --git a/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/bar1.txt b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/bar1.txt new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/bar1.txt diff --git a/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/foo.txt b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/foo.txt new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/foo.txt diff --git a/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/subfolder/test.me b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/subfolder/test.me new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/tycho-packaging-plugin/src/test/resources/projects/validationHelper/binInclude/subfolder/test.me diff --git a/tycho-source-plugin/pom.xml b/tycho-source-plugin/pom.xml index 31b4b02..1ce2abf 100644 --- a/tycho-source-plugin/pom.xml +++ b/tycho-source-plugin/pom.xml @@ -60,6 +60,11 @@ <artifactId>tycho-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-packaging-plugin</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <build> diff --git a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java index 06dbd41..079c84a 100644 --- a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java +++ b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.tycho.source; +import static org.eclipse.tycho.packaging.IncludeValidationHelper.checkSourceIncludesExist; + import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -145,6 +147,7 @@ public class OsgiSourceMojo extends AbstractSourceJarMojo { if (srcIncludesList.isEmpty()) { return Collections.emptyList(); } + checkSourceIncludesExist(p, buildProperties); Resource resource = new Resource(); resource.setDirectory(project.getBasedir().getAbsolutePath()); resource.setExcludes(buildProperties.getSourceExcludes()); |

