Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2019-05-09 13:32:12 +0000
committerAlexander Kurtakov2019-05-09 13:49:44 +0000
commit4222674842f3e55160fd9bc3deb33c6f9f31d260 (patch)
tree932ca0a4dc7f6273b56031e5af4542a91ebdbe10
parent3755bf182bbcea5badaccbb04c4bc26d14bd4eb2 (diff)
downloadorg.eclipse.tycho.extras-4222674842f3e55160fd9bc3deb33c6f9f31d260.tar.gz
org.eclipse.tycho.extras-4222674842f3e55160fd9bc3deb33c6f9f31d260.tar.xz
org.eclipse.tycho.extras-4222674842f3e55160fd9bc3deb33c6f9f31d260.zip
Various changes in source-feature-plugin
* Use try-with-resources. * Expect JUnit4 test instead of catching (JUnit3 style) * Don't use deprecated methods. * Use String.isEmpty. * Bump maven-plugin-testing-harness version to 2.1 Change-Id: Iff36b165c02730c958692a8e5870e2dc2cd3a701 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--tycho-source-feature-plugin/pom.xml2
-rw-r--r--tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java35
-rw-r--r--tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java19
3 files changed, 21 insertions, 35 deletions
diff --git a/tycho-source-feature-plugin/pom.xml b/tycho-source-feature-plugin/pom.xml
index c31261f..b52694c 100644
--- a/tycho-source-feature-plugin/pom.xml
+++ b/tycho-source-feature-plugin/pom.xml
@@ -57,7 +57,7 @@
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<scope>test</scope>
- <version>2.0</version>
+ <version>2.1</version>
</dependency>
</dependencies>
diff --git a/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java b/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
index f197e01..4525518 100644
--- a/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
+++ b/tycho-source-feature-plugin/src/main/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureMojo.java
@@ -38,7 +38,6 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.artifacts.TargetPlatform;
@@ -69,7 +68,8 @@ import de.pdark.decentxml.Element;
* appended to each plugin id</li>
* <li>Includes all features included by &lt;originalFeature&gt;, but each with <code>.source</code>
* appended to each feature id</li>
- * <li>Includes the original feature. This ensures that binaries and corresponding sources match.</li>
+ * <li>Includes the original feature. This ensures that binaries and corresponding sources
+ * match.</li>
* </ul>
*
* Source feature generation can be customized by adding files under path
@@ -216,8 +216,8 @@ public class SourceFeatureMojo extends AbstractMojo {
}
archiver.getArchiver().addFile(sourceFeatureXml, Feature.FEATURE_XML);
archiver.getArchiver().addFile(getMergedSourceFeaturePropertiesFile(), FEATURE_PROPERTIES);
- File licenseFeature = licenseFeatureHelper.getLicenseFeature(
- Feature.read(new File(project.getBasedir(), "feature.xml")), project);
+ File licenseFeature = licenseFeatureHelper
+ .getLicenseFeature(Feature.read(new File(project.getBasedir(), "feature.xml")), project);
if (licenseFeature != null) {
archiver.getArchiver()
.addArchivedFileSet(licenseFeatureHelper.getLicenseFeatureFileSet(licenseFeature));
@@ -241,8 +241,8 @@ public class SourceFeatureMojo extends AbstractMojo {
}
private Properties mergeFeatureProperties(Properties sourceFeatureTemplateProps) throws IOException {
- Properties generatedOriginalFeatureProps = readPropertiesIfExists(new File(project.getBuild().getDirectory(),
- FEATURE_PROPERTIES));
+ Properties generatedOriginalFeatureProps = readPropertiesIfExists(
+ new File(project.getBuild().getDirectory(), FEATURE_PROPERTIES));
Properties mergedProperties = new Properties();
mergedProperties.putAll(generatedOriginalFeatureProps);
mergedProperties.putAll(sourceFeatureTemplateProps);
@@ -273,12 +273,8 @@ public class SourceFeatureMojo extends AbstractMojo {
private static Properties readPropertiesIfExists(File propertiesFile) throws IOException {
Properties properties = new Properties();
if (propertiesFile.isFile()) {
- FileInputStream propertiesStream = null;
- try {
- propertiesStream = new FileInputStream(propertiesFile);
+ try (FileInputStream propertiesStream = new FileInputStream(propertiesFile)) {
properties.load(propertiesStream);
- } finally {
- IOUtil.close(propertiesStream);
}
}
return properties;
@@ -286,11 +282,8 @@ public class SourceFeatureMojo extends AbstractMojo {
private static void writeProperties(Properties props, File propertiesFile) throws IOException {
propertiesFile.getParentFile().mkdirs();
- FileOutputStream out = new FileOutputStream(propertiesFile);
- try {
- props.save(out, "");
- } finally {
- IOUtil.close(out);
+ try (FileOutputStream out = new FileOutputStream(propertiesFile)) {
+ props.store(out, "");
}
}
@@ -320,8 +313,8 @@ public class SourceFeatureMojo extends AbstractMojo {
sourceFeature.setLabel(validateValue(originalLabel, mergedFeatureProperties));
String labelKey = originalLabel.substring(1);
if (sourceTemplateProperties.getProperty(labelKey) == null) {
- mergedFeatureProperties.setProperty(labelKey, mergedFeatureProperties.getProperty(labelKey)
- + labelSuffix);
+ mergedFeatureProperties.setProperty(labelKey,
+ mergedFeatureProperties.getProperty(labelKey) + labelSuffix);
} else {
// keep source template value
}
@@ -401,8 +394,8 @@ public class SourceFeatureMojo extends AbstractMojo {
private void fillReferences(Feature sourceFeature, Feature feature, TargetPlatform targetPlatform)
throws MojoExecutionException {
P2ResolverFactory factory = this.equinox.getService(P2ResolverFactory.class);
- P2Resolver p2 = factory.createResolver(new MavenLoggerAdapter(this.logger, DebugUtils.isDebugEnabled(
- this.session, this.project)));
+ P2Resolver p2 = factory.createResolver(
+ new MavenLoggerAdapter(this.logger, DebugUtils.isDebugEnabled(this.session, this.project)));
List<PluginRef> missingSourcePlugins = new ArrayList<>();
List<FeatureRef> missingSourceFeatures = new ArrayList<>();
@@ -556,7 +549,7 @@ public class SourceFeatureMojo extends AbstractMojo {
return null;
}
attr = attr.trim();
- if (attr.length() == 0) {
+ if (attr.isEmpty()) {
return null;
}
return attr;
diff --git a/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java b/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java
index 5a49c97..68cf916 100644
--- a/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java
+++ b/tycho-source-feature-plugin/src/test/java/org/eclipse/tycho/extras/sourcefeature/SourceFeatureSkeletonTest.java
@@ -17,12 +17,14 @@ import java.util.Properties;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.SilentLog;
-import org.codehaus.plexus.util.IOUtil;
import org.eclipse.tycho.model.Feature;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class SourceFeatureSkeletonTest extends AbstractMojoTestCase {
private SourceFeatureMojo mojo;
@@ -68,26 +70,17 @@ public class SourceFeatureSkeletonTest extends AbstractMojoTestCase {
assertEquals("a hardcoded label Developer Resources", sourceFeature.getLabel());
}
- @Test
+ @Test(expected = MojoExecutionException.class)
public void testFeatureLabelMissingInProperties() throws Exception {
Feature originalFeature = createFeature("/featureWithLabelInProperties.xml");
Assert.assertEquals("%label", originalFeature.getLabel());
Properties emptyProperties = new Properties();
- try {
- Feature sourceFeature = mojo.createSourceFeatureSkeleton(originalFeature, emptyProperties, emptyProperties);
- fail("Expected Exception for label not found");
- } catch (MojoExecutionException ex) {
- // Success
- }
+ mojo.createSourceFeatureSkeleton(originalFeature, emptyProperties, emptyProperties);
}
private Feature createFeature(String fileName) throws IOException {
- InputStream featureStream = null;
- try {
- featureStream = getClass().getResourceAsStream(fileName);
+ try (InputStream featureStream = getClass().getResourceAsStream(fileName)) {
return Feature.read(featureStream);
- } finally {
- IOUtil.close(featureStream);
}
}

Back to the top