Skip to content

Commit

Permalink
#55 - discard packaging of test-fragment (#67)
Browse files Browse the repository at this point in the history
Fix #55 - discard packaging of test-fragment

* revert additional packaging
* remove obsolete test
* remove invalid tests
  • Loading branch information
laeubi committed Apr 21, 2021
1 parent bcd94f0 commit 67dfb7f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
package org.eclipse.tycho.test.surefire;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.Arrays;

import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Test;
Expand All @@ -45,36 +43,4 @@ public void testTest() throws Exception {
new File(verifier.getBasedir(), "target/surefire-reports/bundle.test.AdderTest.txt").exists());
}

@Test
public void testPackage() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "package"));
verifier.verifyErrorFreeLog();
assertTrue("test fragment not found",
new File(verifier.getBasedir(), "target/bundle.test-1.0.0_fragment.jar").exists());
}

@Test
public void testIntegrationTest() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "integration-test"));
verifier.verifyErrorFreeLog();
assertTrue("summary report not found",
new File(verifier.getBasedir(), "target/failsafe-reports/failsafe-summary.xml").exists());
verifier.verifyTextInLog("Tests run: 2, Failures: 1, Errors: 0, Skipped: 0");
verifier.verifyTextInLog("OSGiRunningIT.willFail:30 This fail is intentional");
}

@Test
public void testVerify() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
try {
verifier.executeGoals(Arrays.asList("clean", "verify"));
fail("the build succeed but test-failures are expected!");
} catch (VerificationException e) {
//thats good indeed...
verifier.verifyTextInLog("There are test failures");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
Expand All @@ -39,7 +38,6 @@
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.core.TychoConstants;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
Expand All @@ -48,7 +46,6 @@
import org.eclipse.tycho.core.shared.BuildProperties;
import org.eclipse.tycho.packaging.sourceref.SourceReferenceComputer;
import org.eclipse.tycho.packaging.sourceref.SourceReferencesProvider;
import org.osgi.framework.Constants;

/**
* Creates a jar-based plugin and attaches it as an artifact
Expand Down Expand Up @@ -164,57 +161,6 @@ public void execute() throws MojoExecutionException {

File pluginFile = createPluginJar();
project.getArtifact().setFile(pluginFile);
File testPluginFile = createTestPluginJar(reactorProject);
if (testPluginFile != null) {
projectHelper.attachArtifact(project, "jar", ArtifactType.TYPE_ECLIPSE_TEST_FRAGMENT, testPluginFile);
}
}

private File createTestPluginJar(ReactorProject reactorProject) throws MojoExecutionException {
File testOutputDirectory = reactorProject.getBuildDirectory().getTestOutputDirectory();
if (!testOutputDirectory.isDirectory() || testOutputDirectory.list().length == 0) {
return null;
}

JarArchiver archiver = new JarArchiver();

File fragmentFile = new File(buildDirectory, finalName + "_fragment.jar");
if (fragmentFile.exists()) {
fragmentFile.delete();
}
File manifest = new File(project.getBuild().getDirectory(), "FRAGMENT_MANIFEST.MF");
try {
Manifest bundleManifest = getManifest();
Manifest fragmentManifest = new Manifest();
Attributes attributes = fragmentManifest.getMainAttributes();
attributes.put(Name.MANIFEST_VERSION, "1.0");
attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
attributes.putValue(Constants.BUNDLE_NAME, "Test Fragment for " + project.getGroupId() + ":"
+ project.getArtifactId() + ":" + project.getVersion());
String hostVersion = bundleManifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
String hostSymbolicName = bundleManifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
attributes.putValue(Constants.BUNDLE_VERSION, hostVersion);
attributes.putValue(Constants.BUNDLE_SYMBOLICNAME, hostSymbolicName + ".test");
attributes.putValue(Constants.FRAGMENT_HOST,
hostSymbolicName + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=\"" + hostVersion + "\"");
Collection<String> additionalBundles = pdeProject.getBuildProperties().getAdditionalBundles();
if (!additionalBundles.isEmpty()) {
attributes.putValue(Constants.REQUIRE_BUNDLE, String.join(",", additionalBundles));
}
attributes.putValue(Constants.DYNAMICIMPORT_PACKAGE, "*");
writeManifest(manifest, fragmentManifest);
} catch (IOException e) {
throw new MojoExecutionException("Update Manifest failed", e);
}
archiver.setManifest(manifest);
archiver.setDestFile(fragmentFile);
archiver.addDirectory(testOutputDirectory);
try {
archiver.createArchive();
} catch (IOException | ArchiverException e) {
throw new MojoExecutionException("Error assembling test JAR", e);
}
return fragmentFile;
}

private void createSubJars() throws MojoExecutionException {
Expand Down

0 comments on commit 67dfb7f

Please sign in to comment.